又见 Jquery Ajax Post乱码
var contents = encodeURIComponent(document.getElementById("content-"+id).value);
//var contents = document.getElementById("content-"+id).value;
var castellanId = document.getElementById("castellan-"+id).value;
alert(contents);
if (handleType == 'read') {
$.post('handleSuggestDomainAction.action', {
sbt: 'sbrd',
content: contents,
cid: castellanId,
sgId: id
}, function() {
//alert('哈哈.回复/处理成功!');
window.location.href =window.location.href;
window.location.href.reload();
//window.location.reload();
});
}
环境: Jquery1.3.2 ,Struts2
页面:
jsp中,改成红色显示的那样
var contents = encodeURIComponent(document.getElementById("content-"+id).value);
服务器端:
contentCn = URLDecoder.decode(content, "UTF-8");
乱码解决..
以前记得要页面上 encode 2次的.貌似记错了?
好用,如果前台用escape,后台解不了码,只能用这种办法了。
js中要进行两次encode才可以。没错。