2012-02-07 106 views
0

我一直在使用這個腳本一段時間,突然它只是停止工作,並返回錯誤信息。我找不到任何與代碼有關的錯誤,並且php頁面會迴應有效的json。如果任何人都可以找到這個代碼的錯誤或錯誤,請告訴我。我在其他地方使用相同的腳本就好了。jquery函數停止工作

前往: http://ab-mobile-apps.com/app/grotto/index.html 然後點擊隨機飲料看直播。單擊錯誤消息將再次調用該函數。

提前感謝。

function loadData() {        
    var output = $('#output'); 
    var drinkImageOutput = $('#drinkImage'); 
    var drinkIngredientOutput = $('#drinkIngredient'); 
    var drinkNameOutput = $('#drinkName'); 

    output.text(''); 

    $.ajax({ 

     url: 'http://ab-mobile-apps.com/grototest/index.php', 
     dataType: 'jsonp', 
     jsonp: 'jsoncallback', 
     timeout: 10000, 
     success: function(data, status){ 
     $.each(data, function(i,item){ 
     var landmark = 
      '<div id="drinkImage"><img src="' + drinkImg + '" width="15%" /></div>' + 
      '<div id="drinkName">' + drinkName + '</div>' + 
      '<div id="dringIngredient">' + dringIngredient + '</div>'; 


     output.append(landmark); 
     }); 
     }, 
     error: function(){ 
     output.text('There was an error loading the data.'); 
     } 
    });    
} 
+2

使用調試器在Chrome瀏覽器步執行代碼... – Kris 2012-02-07 23:39:36

+0

調升您的評論克里斯和進一步闡述,在Chrome瀏覽器開發工具(按F12打開),進入網絡選項卡..在那裏你會看到AJAX請求並找出返回的內容,從那裏你應該可以調試你的腳本 – 2012-02-07 23:44:28

+0

我很感謝你的迴應。在發佈之前,我使用chrome多次調試腳本,並且ajax調用似乎被跳過。你有沒有試過它與我張貼的網址。請做並提供反饋。 – skwidgets 2012-02-08 00:18:12

回答

1

您的請求返回JSON而不是JSONP。 嘗試:

$.ajax({ 
    url: 'http://ab-mobile-apps.com/grototest/index.php', 
    dataType: 'json', 
    timeout: 10000, 
    success: function(data, status){ 
    $.each(data, function(i,item){ 
    var landmark = 
     '<div id="drinkImage"><img src="' + item.url + '" width="15%" /></div>' + 
     '<div id="drinkName">' + item.sname + '</div>' + 
     '<div id="dringIngredient">' + item.ingredients + '</div>'; 


    output.append(landmark); 
    }); 
    }, 
    error: function(){ 
    output.text('There was an error loading the data.'); 
    } 
});