jquery - Internet Explorer 9 给出 parseJSON 错误

标签 jquery json internet-explorer-9 jquery-1.9

我不知道这是由 jQuery 还是由我的脚本引起的。这是 Internet Explorer 9 给出错误的地方:

parseJSON: function( data ) {
    // Attempt to parse using the native JSON parser first
    if ( window.JSON && window.JSON.parse ) {
        return window.JSON.parse( data ); <<< this the "Invalid Character" err.
    }

这是我的 JavaScript 代码

http://jsfiddle.net/fNPwh

根据我的研究,我还检查了我的 DOCTYPE 在这里。他们正在谈论 Quirks 模式,所以我也尝试放置 x-ua-兼容 但没有任何改变

<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
<meta http-equiv="content-style-type" content="text/css" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" > <!-- IE9 mode -->
blabla

为什么 ie9 会给出 jQuery 的无效字符错误?而不是 firefox 或 webkit。哦,顺便说一句,我正在使用 jQuery 1.9.1。

最佳答案

这似乎是 jQuery 库中的一个错误。 This post包含用于修复的添加/修改代码。基本上只需在尝试解析之前移动对 null 的检查并添加对 undefined 的检查即可。该方法的开始应该如下所示...

parseJSON: function( data ) {
    if (data === undefined) {
        return data;
    }
    if (data === null) {
        return data;
    }

    // Attempt to parse using the native JSON parser first
    if ( window.JSON && window.JSON.parse ) {
        return window.JSON.parse( data );
    }
...

我已在 IE10 和 Chrome 中验证了此修复。

关于jquery - Internet Explorer 9 给出 parseJSON 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15308471/

相关文章:

javascript - DataTables (JQuery) 如何对给定包含数据的数组进行多列过滤文本框?

python - 将curl命令从google-colab转换为python脚本

html - IE9奇怪的黑边

css - IE9 中的渐变 : using "filter: none" doesn't work

javascript - 替换 "hidden input"的替代方案

javascript - 如何在 JavaScript 中匹配给定日期差异之间的日期

json - 如何说服 VS code 接受 # 作为 JSON 文件中的注释?

javascript - Internet Explorer 9 对象检测

javascript - 在 CSS/jQuery 中的旋转元素上保持相同方向的阴影

c# - 使用可变属性名称反序列化 JSON