jquery的ajax向后台提交时,乱码的解决方案

时间:2023-03-09 19:27:52
jquery的ajax向后台提交时,乱码的解决方案

1. 可以给每个参数加上encodeURIComponent(),然后在后台获得参数后用URLDecoder.decode(string, 'utf-8')解码。

2. 后台不用解码。

              $.ajax({
url : '',
type : 'post',
contentType: "application/x-www-form-urlencoded; charset=utf-8",
data : {
serialNum : serialNum,
conditionString : conditionString,
},
success : function(msg){
alert(msg);
},
error : function(msg){
alert(msg);
}
});