2014-09-11 75 views
0

如標題所示,我有jsonp跨域ajax查詢。它返回json列表和我可以監視它從螢火蟲,但在jQuery的ajax功能錯誤:部分工作,儘管錯誤狀態200 OK,狀態文本成功。調用jsonp類型ajax在firebug中返回json,但在ajax中觸發錯誤

我無法訪問遠程服務器,因此我無法配置CORS。遠程服務器只提供返回json列表的webservice。

- 我的AJAX功能

$.ajax({ 
    crossDomain: true, 
    type: 'GET', 
    url: "url/for/json", 
    dataType: "jsonp",   
    success: function(data, success){ 
     console.log(" success "); 
    }, 
    error: function(error){ 
      alert(JSON.stringify(error)); 
     }, 
}); 

--response的螢火

firebug screenshot

- 兼警報稱爲誤差部分(裏面沒有成功拼命地跑代碼)

enter image description here

返回的json我的測試是有效的。

我可以在firebug中監控我所有的json數據,一切正常,但我無法訪問瀏覽器內部的數據(javascript)。我嘗試了幾乎所有我在網上發現的一切,但沒有任何幫助。是否有響應

回答

0
$.ajax({ 
    crossDomain: true, 
    type: 'GET', 
    url: "url/for/json", 
    dataType: "jsonp",   
    success: function(data, success){ 
     console.log(" success "); 
     console.log(data) // here you will have access to the response. 
    }, 
    error: function(error){ 
      alert(JSON.stringify(error)); 
     }, 
}); 

在成功回調來訪問數據的方式,你將有機會獲得返回的數據。

+0

我試過了。但成功部分內的任何代碼都不會被編譯,即。 ajax直接調用錯誤部分。 – Erlan 2014-09-11 12:06:26