$.ajax({
type: "POST",
dataType:"json", //如果返回数据是JSON格式,dataType请指定json
url: "inputCodeAction",
data: "dictType=" + $(this).attr("dictType") + "&inputText=" + obj.value + "&random=" + Math.floor(Math.random() * 10000 + 1),
success: function(result){
alert(result);
}
type: "POST",
dataType:"json", //如果返回数据是JSON格式,dataType请指定json
url: "inputCodeAction",
data: "dictType=" + $(this).attr("dictType") + "&inputText=" + obj.value + "&random=" + Math.floor(Math.random() * 10000 + 1),
success: function(result){
alert(result);
}
});
type属性值改为"POST"时,action不会出现中文乱码问题
dataType属性可以设置为xml,json,script,html多种返回格式!

本文探讨了在AJAX中使用POST方法时,数据类型选择对于防止中文乱码问题的重要性,并详细介绍了如何通过设置dataType属性为json来解决跨域传输中文字符导致的乱码问题。同时,文章还阐述了dataType属性支持的多种数据返回形式,包括xml, json, script, html等,以适应不同场景需求。
5953

被折叠的 条评论
为什么被折叠?



