错误JSON未定义

Error JSON is undefined

本文关键字:未定义 JSON 错误      更新时间:2023-09-26

我在internet explorer 'JSON' is undefined上遇到此错误。

错误发生在这里:

ajaxCall({
    url: me.getAllService,
    data: JSON.stringify(unionParameters({ filter: filter }, getData(), me.getAllParameters)),
    success: function (result) {
        if (typeof (onSuccess) == 'function')
            onSuccess(result);
    },
    error: function (error) {
        if (typeof (onFailed) == 'function')
            onFailed(error);
    }
});

JSON解析功能出现在IE8中。如果使用IE7或更早版本,则JSON将未定义。

此外,如果您正在使用IE8,它必须处于标准模式。在怪癖模式下,JSON格式化程序将不可用。

在任何情况下,都有可用的polyfill,因此您可以在这些情况下使用JSON格式化程序。向下滚动至"JavaScript"http://www.json.org/四种可能性。

来源/附加信息:

  • http://caniuse.com/#feat=json
  • https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify

使用JSON2。这是你需要的polyfill

http://cdnjs.com/libraries/json2

我通过在主页中添加以下代码行解决了这个问题:

<meta http-equiv="X-UA-Compatible" content="IE=9" />