最近有朋友反映使用jquery.ajax调用返回json时出现中文乱码,遇到此问题,非常棘手,下面我帮大家解决jquery ajax 返回json时出现中文乱码问题,感兴趣的朋友跟着一起了解了解吧
使用jquery ajax调用的返回json,中文乱码问题
js代码如下:
$.ajax({
url: '/test/testaction.do?method=test',
type: 'post',
datatype: 'json',
timeout: 5000,
async: false,
error: function(){
alert('获取数据失败!');
},
success: function(json){
jsobject = eval(json);
}
});
return jsobject;
js代码
<span style="font-size: x-small;">$.ajax({
url: '/test/testaction.do?method=test',
type: 'post',
datatype: 'json',
timeout: 5000,
async: false,
error: function(){
alert('获取数据失败!');
},
success: function(json){
jsobject = eval(json);
}
});
return jsobject;</span>
action:
java代码
jsonarray json = jsonarray.fromobject(syslist);//syslist是一个list
// 设置response的contenttype解决中文乱码
response.setcontenttype("text/html;charset=utf-8");
response.getwriter().print(json.tostring());
return null;
java代码
<span style="font-size: x-small;">jsonarray json = jsonarray.fromobject(syslist);//syslist是一个list
// 设置response的contenttype解决中文乱码
response.setcontenttype("text/html;charset=utf-8");
response.getwriter().print(json.tostring());
return null;</span>
上面是我整理给大家的,希望今后会对大家有帮助。
相关文章:
django框架如何使用ajax的post方法
django中使用jquery ajax post数据出现403错误的解决办法
详解ajax +jtemplate实现动态分页
以上就是jquery ajax 返回json时出现中文乱码该如何解决的详细内容。