我不知道这是由 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 代码
根据我的研究,我还检查了我的 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/