[英]getJSON callback function not executed
我在名為reqfiled.json的文件中遵循了JSON
{
"Activity List View" :
{
"Activity Form Applet":{
"Asset Number": "Y",
"Type":"Y",
"Comment":"Y",
"Status":"Y",
"Priority":"Y"
}
}
}
我有以下jQuery代碼
$.getJSON("23030/scripts/siebel/custom/reqfield.json", function(data) {
console.log("hi");
});
但是回調函數不會執行。 我已經在firebug和chrome net選項卡中檢查了調用是否成功完成,並作為響應返回了json數據。
還有什么可能是問題,我該如何調試?
您可能使用了錯誤的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');
});
我還要在console.log(data)
行(這是console.log('hi');
console.log(data)
設置一個斷點,這僅僅是因為如果您說文件確實已發送,那么我想知道請確保json文件僅包含JSON數據,並再次檢查控制台以查看getJSON
調用后可能發生的任何JS警告/錯誤。
我還沒有檢查jQ如何處理這些json文件,但是我不確定100%是否設置了格式。 最好在控制台中寫出文字,然后將JSON.stringify
的輸出復制粘貼到該文件中:)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.