jQuery的IE9 JSON.SyntaxError parseerror,但JSON是有效的 [英] jQuery IE9 JSON.SyntaxError parseerror, but JSON is valid

查看:127
本文介绍了jQuery的IE9 JSON.SyntaxError parseerror,但JSON是有效的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些jQuery(1.6.2,最新的稳定)code这是工作在Chrome,火狐,Safari浏览器,IE7和IE8 ...但IE9未能解析我json的Ajax响应。 JSON的是有效的,我已经通过 http://jsonlint.com/

I've got some jQuery (1.6.2, latest stable) code which is working in Chrome, Firefox, Safari, IE7 and IE8... but IE9 is failing to parse my json ajax response. The json is valid and I've run it through http://jsonlint.com/

$.ajax({
    url: lookupURL,
    dataType: "json",
    cache: false, // don't cache the result
    contentType: "application/json", //tell the server we're looking for json
    success: function(data) {
        // do stuff with result
    },
    error: function(xhr, errorString, exception) {
        alert("xhr.status="+xhr.status+" error="+errorString+" exception=|"+exception+"|");
    }
});

错误处理程序是一个jQuery的调用(IE9只)。该xhr.status = 200,为errorString = parseerror和异常=的SyntaxError JSON.parse

The error handler is the one jQuery calls (IE9 only). The xhr.status=200, the errorString=parseerror and the exception=SyntaxError JSON.parse

我的JSON是有效的,我甚至使用的最终简单的JSON字符串检查:

My json IS valid and I've even checked with using an ultimately simple json string:

{"foo":"bar"}

我已经使用xhr.responseText有没有领先或在JSON尾随空格验证。

I have verified using xhr.responseText that there are no leading or trailing spaces on the json.

这是为什么失败的IE9?

Why is this failing in IE9?

推荐答案

发现问题。我正与该系统是一个相当大的CMS和电子商务的框架,所以他们的JavaScript在自己的图书馆很多。内心深处,他们的js的一个库被替代全局JSON对象,并提供自己的实现JSON.parse的。它看起来就像是从json.org的老年人和/或砍死json2的版本。当试图解决这个问题前,我曾试图安装json2为JSON对象无济于事......但事实证明,他们当时弄错我的json2与他们的。我把我的安装json2中要加载的最后一个javascript和现在它正在工作。我不知道什么是IE9的影响只有一个......但你去。

Found the problem. The system I'm working with is a fairly large CMS and E-Commerce framework, so they have a LOT of javascript in their own libraries. Deep inside one of their js libraries they were replacing the global JSON object and providing their own implementation of JSON.parse. It looks like it was an older and/or hacked version of json2 from json.org. When trying to solve the problem earlier, I had tried installing json2 as the JSON object to no avail... but it turned out they were then clobbering my json2 with theirs. I moved my installation of json2 to be the last javascript loaded and now it is working. I don't know what IE9 was the only one affected... but there you go.

这篇关于jQuery的IE9 JSON.SyntaxError parseerror,但JSON是有效的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆