jQuery ajax中默認的是utf-8編碼,所以在傳輸中文時會出現亂碼。
解決方法:
請求端:
在js方法中將要傳輸的中文數據重新編碼:
inputVal = encodeURI(inputVal); //inputVal 爲中文字符串變量
接收端:
String inputVal = StringUtil.format(request.getParameter("inputVal"));
inputVal = java.net.URLDecoder.decode(inputVal,"utf-8");
以上方法就可以解決傳輸中文亂碼問題