IE8使用ajax提交json对象
举例
以下是一段包含ajax的方法,在IE8中使用将爆出json未定义的错误。
$(function () {
var content = new Object();
content.id = 1;
content.name = 'dongri';
$.ajax({
url: '/UserAccount/checkVoucher',
data: JSON.stringify(content),
type: 'post',
dataType: 'json',
contentType: 'application/json; charset=utf-8',
success: function (result) {
if (result.result == "1") {
location.href = "/UserAccount/TransDataToBank?istrans=0";
}
else {
art.dialog.alert("请勿重复支付");
}
},
error: function () {
alert("网络异常,请重试");
location.reload();
}
});
});
解决方案
引入一个js文件,名称为:json2.json,引入这个js文件之后代码不需要改动,将直接兼容IE8。
链接地址为https://github.com/douglascrockford/JSON-js