get 方式提交數據到服務端不會亂碼,但對數據量有限制;post 可以提交大數據量,但中文會發生亂碼,解決方法:
在JS上用使用 encodeURIComponent 對字符編碼處理:
studentRuselt=encodeURIComponent(JSON.stringify(result),"utf-8"); //這里用了json2 來將對象轉換為json格式,然后在用encodeURIComponent來設置編碼; $.ajax({ type:"post", url:"saveExamQuestionAnswer.action", cache:true, async:true, //這里指定值時不能加雙引號(會設置無效) contentType: "application/x-www-form-urlencoded; charset=utf-8", data: { studentRuselt: studentRuselt } )};