AJAX 中文参数 需要编码后传给服务端,然后在服务端用utf-8解码,因为ajax(post请求)默认是utf-8编码;
如:js
ajax.setParam("topic.content", encodeURIComponent(f["topic.content"].value));
java:
URLDecoder.decode(topic.getContent(), "utf-8")
----------------------------------------------------------------------------------------------------------
utf-8
encodeURIComponent <------------------------->URLDecoder.decode
而get的请求则不一样;get请求不走filter
需要在js端用两次编码:
encodeURIComponent(encodeURIComponent(f["topic.content"].value))。
【http://hi.baidu.com/tianqinhot/blog/item/7db95f598080192c2934f02c.html】
本文介绍了在使用AJAX进行数据传输时如何正确处理UTF-8编码问题,包括POST请求中的参数编码及解码方式,以及GET请求中特殊情况下需要进行的双重编码操作。

被折叠的 条评论
为什么被折叠?



