jQuery Internet Explorer 7 中的 JSON 问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4956076/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 18:16:47  来源:igfitidea点击:

Problem with JSON in Internet Explorer 7

jqueryjsoninternet-explorer-7undefined

提问by feronovak

IE8/Chrome,FF work well but Internet Explorer 7 is giving me headaches.

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

I am trying to get numeric result for actual form

我正在尝试获取实际形式的数字结果

$(".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) {
}

What have I done wrong that IE7 wont work?

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

Thanks

谢谢

回答by Daniel

JSON.stringify is not part of IE7.

JSON.stringify 不是 IE7 的一部分。

You'll have to use Douglas Crockford's JavaScript implementation of this:

您必须使用 Douglas Crockford 的 JavaScript 实现:

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

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

More specifically this script:

更具体地说,这个脚本:

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

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

It will add the stringify and parse methods to browser that do not natively implement this (like IE7 and below)

它将向浏览器添加 stringify 和 parse 方法,这些方法不是本机实现的(如 IE7 及以下)