简体   繁体   English

无法使用 jQuery 检索特定的 JSON 对象

[英]Unable to retrieve particular JSON objects using jQuery

I try to retrieve a JSON object with jQuery from a server.我尝试从服务器检索 JSON object 和 jQuery。 Some properties of this object are arrays. When these arrays are not empty, I'm able to process my object. But when I retrieve a JSON like this one:这个 object 的一些属性是 arrays。当这些 arrays 不为空时,我可以处理我的 object。但是当我像这样检索 JSON 时:

{"Id":144,"Identifier":"4000011","ContractId":115,"ContractName":"Test4","Meters":[],"Scans":[]}

where "Meters" and "Scans" are empty, jQuery raises an error... I query my server with this code:其中“Meters”和“Scans”为空,jQuery 引发错误...我使用以下代码查询我的服务器:

    $("#test").click(function () {

        $.ajax({
            type: "GET",
            url: "/Gateway/GetDetails/144",
            data: {},
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (data, textStatus, jqXHR) {

               ...

            },
            error: function (jqXHR, textStatus, errorThrown) { 
               ...
            }
    });

In the error handler, I can see my JSON object in the responseText property of the parameter "jqXHR".在错误处理程序中,我可以在参数“jqXHR”的 responseText 属性中看到我的 JSON object。 Did you encounter this problem?你遇到过这个问题吗?

Thanks in advance !提前致谢 !

The JSON you've supplied is valid (as confirmed by the JSON Lint tool);您提供的 JSON 有效(经JSON Lint工具确认); is it possible that the Server you are querying is returning an HTTP Error Status Code, or that an internal error is happening on the server side.您正在查询的服务器是否可能返回 HTTP 错误状态代码,或者服务器端发生内部错误。 You can confirm this by using a debugging proxy like Firebug , Chrome Developer tools .您可以使用调试代理(如FirebugChrome 开发人员工具)来确认这一点。

I answer my own question... First I tested only with Inte.net Explorer 9;我回答我自己的问题...首先我只使用 Inte.net Explorer 9 进行测试; with an other browser, all worked as expected.使用其他浏览器,一切都按预期工作。 After I cleared the Inte.net Explorer cache, the problem disappeared.清除 Inte.net Explorer 缓存后,问题消失了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM