关于ajax $.post() 返回乱码问题
2011-11-11 11:15
225 查看
一直出现乱码,关键在这里,请看这两段代码的区别
Gson gson = new Gson(); String str = gson.toJson(users); response.setContentType("application/json; charset=utf-8"); response.setHeader("pragma", "no-cache"); response.setHeader("cache-control", "no-cache"); PrintWriter out = response.getWriter(); out.println(str); out.flush();
Gson gson = new Gson(); String str = gson.toJson(users); PrintWriter out = response.getWriter(); response.setContentType("application/json; charset=utf-8"); response.setHeader("pragma", "no-cache"); response.setHeader("cache-control", "no-cache"); out.println(str); out.flush();
response.setContentType("application/json; charset=utf-8");//前者没有乱码,后者有乱码,关键在于这句话的位置
相关文章推荐
- tomcat发布项目 ajax方式post请求返回数据中文乱码问题(Eclipse中tomcat正常)
- ajax返回中文乱码,servlet中的显示乱码,post提交的乱码问题,编码大总结
- 关于 Ajax Post 的乱码问题处理方法
- 关于$.ajax 返回返回值问题
- httpurlconnection post 和GET 分别传递2个参数给后台,返回JSON 解决乱码问题
- Windows 下 Tomcat 部署 maven项目 POST 返回中文乱码问题
- SpringMVC Ajax返回的请求json 的方式来解决在中国字符串乱码问题
- mvc中使用ajax传数据到控制层再返回json已经乱码问题
- 关于HttpClient 发送Post请求带string参数,接收乱码问题
- 关于post文件上传不能返回路径问题的解决方案
- 关于ajax中文乱码问题
- 利用jquery实现Ajax技术,post方式传值中文乱码问题的解决办法。
- ajax,Struts2返回字符串乱码问题
- 关于tomcat或jetty布署grails时ajax中文乱码的问题
- Ajax使用POST提交中文乱码问题(转)
- ajax请求数据,Json返回到页面的数据出现中文乱码问题。
- ajax返回中文乱码问题解决
- 关于处理JavaWeb中Servlet中返回jsp乱码问题
- 【笔记】关于jq $.ajax 函数 success回调函数不能赋正确值或返回正确值的问题
- 关于多个Ajax请求执行返回先后的问题