2014-02-06 66 views
0

我有一個JSON GET請求,當我使用curl在PHP把它完美的作品,但是當我嘗試做同樣的事情的getJSON(這是要求),所有我回來當我使用下面的代碼時,狀態是錯誤的。我怎樣才能確切知道錯誤是什麼?我不知道如果我發送錯誤參數的請求是否超時,或者它可能是什麼。由於捲曲工作,JSON不工作

  $.getJSON(url, function(data,status,xhr) { 
      if (status == "success"){ 
    alert ("got the data"+data); 
}else if (status == "timeout"){ 
    alert("Something is wrong with the connection"); 
}else if (status == "error" || status == "parsererror"){ 
    alert("An error occured"); 
}else{ 
    alert("datatosend did not change"); 
}  
     }) 
+0

您可能會被同源策略阻止?錯誤說的是什麼? – adeneo

+0

'console.log(xhr.status,xhr.statusText);' – epascarello

回答

0

的答案是,雖然我是在同一個域,我不把該URL的HTTPS拿到這是我的網站是用什麼。

謝謝

1

我怎麼能知道錯誤是什麼

的答案,至少有:

$.getJSON(url, function(data,status,xhr) { 
    alert ("got the data"+data); 
}).fail(function(a,b,c) { 
    console.log(a,b,c); 
}); 

我猜CORS錯誤和同源策略因爲它與cURL一起工作,如果是這種情況,它不是你的服務器,除了回到使用cURL之外沒有什麼可以做的,對我來說這聽起來像是一個更好的方法。