时间:2021-07-01 10:21:17 帮助过:5人阅读
使用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>相信看了本文案例你已经掌握了方法,更多精彩请关注Gxl网其它相关文章!
推荐阅读:
JSONP解决ajax跨域问题(附代码)
AJAX二级联动有哪些实现方法
以上就是jquery+ajax返回json中文乱码现象怎样处理的详细内容,更多请关注Gxl网其它相关文章!