« | August 2025 | » | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | | | | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | | | | |
| 公告 |
暂无公告... |
Blog信息 |
blog名称: 日志总数:2 评论数量:0 留言数量:0 访问次数:26536 建立时间:2010年2月21日 |

| |
[客户端技术]DOJO的i/o系统  日后处理, 软件技术
louisan 发表于 2010/2/24 10:03:14 |
DOJO的i/o系统
读者提示:水平有限,欢迎留言改正充实文章内容,并提出意见和建议。请不要书写与文章内容无关留言。
正文:待
问题代码片段:
dojo.io.iframe.send({ contentType: "multipart/form-data", form: dojo.byId('form1'), url: "/test/upload/upload.do" , method: "get" , handleAs: "html" , handle: function(res, ioArgs){ dojo.style(result.domNode, {"height":"70%"}); alert(res.body.textContent); result.attr('content', res.body.textContent); }, error: function(error){ console.log(error); } });
问题描述:
1 正常想要返回的是text格式的结果,但会报异常“ifd.getElementsByTagName("textarea")[0] is undefined”
2 返回中文结果时乱码
问题分析:
1 handleAs除非用html 类型(也可以是xml类型,请自行测试),其他类型会要求用<textarea></textarea>包装,否则会提示错误:ifd.getElementsByTagName("textarea")[0] is undefined
例如,后台返回结果: String result="<textarea>success成功</textarea>";可会在页面出现个文本区域
2 字符编码问题
解决方法:
1 handleAs采用html类型
2
* 在服务器端转换返回结果的字符编码:
String result="success成功"; try { result=new String(result.getBytes(request.getCharacterEncoding()),response.getCharacterEncoding()); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }
或者
* 统一字符编码
response.setCharacterEncoding(request.getCharacterEncoding());
疑问:定义的返回结果(result)为什么与request的编码(UTF-8)相同,而不是Charset.defaultCharset().name(),即GBK,是容器(Tomcat)的设置引起的? |
|
|