Jquery - Ajax Call的中文乱码问题
在Java中,有时会碰到奇怪的中文乱码问题,无论是在web.xml中设置相关的utf-8/gbk2312 filter,还是在js中或者在java中进行编码的encode和decode都会出现中文乱码问题。如下代码所示:
function loadParentOrg() {
var url = "getOrgsByLevel.patrol?level=中文";
alert(url);
$.ajax({
url: url,
async: true,
type: 'post',
success: function(organizations){
// alert(organizations);
}
})
}如上所示,将中文写在url中,无论是type为post还是type为get,都会出现中文乱码问题。
解决中文乱码的最好方式是使用post的方式(type:'post')并且将发送的数据写在data字段中,如下所示:
function loadParentOrg() {
var url = "getOrgsByLevel.patrol";
alert(url);
$.ajax({
url: url,
async: true,
type: 'post',
data: {
level:$("#level").val()
},
success: function(organizations){
// alert(organizations);
}
})
} 相关推荐
chongxiaocheng 2020-08-16
ppsurcao 2020-06-14
wcqwcq 2020-06-26
delmarks 2020-06-14
tthappyer 2020-06-07
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
learningever 2020-09-19
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03