jQuery AJAX中文乱码问题

1. jQuery AJAX 请求,后台收到为乱码

可以显式设置contentType的编码为utf-8, 后台一般都能正常解码例如:

[javascript]  view plain  copy
  1.   

 

	

2.  jQuery AJAX 返回乱码

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		String age = request.getParameter("age");
		
		System.out.println(name + ", " + age);
		response.setContentType("text/html;charset=UTF-8"); //设置返回中文编码格式
		response.getWriter().write("{\"name\":\"" + name + "\",\"age\":" + age + "}");
	}

你可能感兴趣的:(jQuery AJAX中文乱码问题)