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
}
)};