简体   繁体   English

getJSON回调函数未执行

[英]getJSON callback function not executed

I have following JSON in a file named reqfiled.json 我在名为reqfiled.json的文件中遵循了JSON

{
"Activity List View" :
    {
    "Activity Form Applet":{
        "Asset Number": "Y",
        "Type":"Y",
        "Comment":"Y",
        "Status":"Y",
        "Priority":"Y"
        }
    }
}

I have following jQuery code 我有以下jQuery代码

$.getJSON("23030/scripts/siebel/custom/reqfield.json", function(data) {
                console.log("hi");
            });

But the callback function doesn't execute. 但是回调函数不会执行。 I have checked the in firebug and chrome net tab the call completed successfully and in response the json data was returned. 我已经在firebug和chrome net选项卡中检查了调用是否成功完成,并作为响应返回了json数据。

What else could be the problem and how to do I debug it? 还有什么可能是问题,我该如何调试?

You're probably using a wrong url/path, but to make sure, add a couple of callbacks to be called in specific cases: 您可能使用了错误的url /路径,但是要确保在特定情况下添加了两个要调用的回调:

$.getJSON("23030/scripts/siebel/custom/reqfield.json", function(data)
{
    console.log(data);
}).fail(function()
{
    console.log('error');
    console.log(arguments);//<-- check these for clues
}).always(function()
{//add this to check if your code even gets executed...
    console.log('getJSON called');
});

I'd also set a breakpoint on the console.log(data) line (which is console.log('hi'); in your code, simply because if you say the file is indeed sent, then I'd want to know where things go wrong. Make sure the json file contains only JSON data, and also double-check the console to see any JS warnings/errors that may occur after the getJSON call. 我还要在console.log(data)行(这是console.log('hi'); console.log(data)设置一个断点,这仅仅是因为如果您说文件确实已发送,那么我想知道请确保json文件包含JSON数据,并再次检查控制台以查看getJSON调用可能发生的任何JS警告/错误。
I haven't checked how jQ processes these json files yet, but I'm not 100% sure about your formatting. 我还没有检查jQ如何处理这些json文件,但是我不确定100%是否设置了格式。 Best write out the literal in your console, and then copy-paste the output of JSON.stringify into that file :) 最好在控制台中写出文字,然后将JSON.stringify的输出复制粘贴到该文件中:)

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

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