Internet Explorer 7中的JSON问题

fer*_*vak 16 jquery json undefined internet-explorer-7

IE8/Chrome,FF运行良好,但Internet Explorer 7令我头疼.

我试图获得实际表格的数字结果

$(".checklist label").click(function () {
    checkResults();
});

function checkResults() {
    var str = $("form").serializeArray();
    $.ajax({
        type: "POST",
        url: "/data.asmx/GetTotal",
        cache: false,
        contentType: "application/json; charset=utf-8",
        data: JSON.stringify({ data: str }),
        dataType: "json",
        success: handleHtml,
        error: ajaxFailed
    });
}

function handleHtml(msg) {
    $("#result").text(msg.d);
}

function ajaxFailed(xmlRequest) {
}
Run Code Online (Sandbox Code Playgroud)

IE7无法正常工作,我做错了什么?

谢谢

Dan*_*iel 30

JSON.stringify不是IE7的一部分.

您将不得不使用Douglas Crockford的JavaScript实现:

https://github.com/douglascrockford/JSON-js

更具体地说这个脚本:

https://github.com/douglascrockford/JSON-js/blob/master/json2.js

它会将stringify和parse方法添加到本机不实现此功能的浏览器中(如IE7及以下版本)

  • 顺便说一句,您不必使用json stringify,因为$ .ajax中的数据参数可以使用整个对象. (5认同)