Ajax 的post請求值返回到js中時出現中文亂碼的狀況,可是在action中寫入時並未亂碼,解決辦法在action中寫入前,加上這兩行:html
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
********************************************************************json
try { //保證返回值中文的時候不亂碼 request.setCharacterEncoding("utf-8"); response.setContentType("text/html;charset=utf-8"); response.getWriter().write(json); } catch (IOException e) { e.printStackTrace(); } return null; }
**************************************************************************************************post
如若轉載請註明出處,謝謝。By奮鬥的小蘑菇spa