1. Ajax跨域访问乱码
解决方式一:
Tomcat的connector中设置URIEncoding="UTF-8"
解决方式二:
var params = {};
var arrParams = $("#openAccountForm").serializeArray();
$(arrParams).each(function(){
if(this.name == "userName"){
params[this.name] = encodeURIComponent(this.value);
}else{
params[this.name]=this.value;
}
});
$.ajax({
url: url,
data: params,
dataType: "jsonp",
jsonp: "jsonpCallback",
//contentType: "application/x-www-form-urlencoded;charset=utf-8",
success: function (data) {
}, error: function () {
}
});
后台:
String userName = req.getUserName();
userName =URLDecoder.decode(userName, "utf-8");