2013-02-23 76 views
0
$.ajax({ 
    url:"myurl", 
    async:true, 
    success:function (data) { 
     //.... 
    }, 
    complete:function (x, st) { 
     //.... 
    }, 
    error:function (x, st, e) { 
     alert(JSON.stringify(x)); 
    } 
}); 

這是ajax調用。 如果我嘗試訪問瀏覽器中的「myurl」,它可以正常工作。 但Ajax調用總是導致錯誤。 如果我的字符串化XHR,它看起來像這樣:AJAX調用結果爲狀態0

{ 
    "readyState": 0, 
    "responseText": "", 
    "status": 0, 
    "statusText": "error" 
} 
+2

您是否檢查控制檯/網絡選項卡是什麼導致了錯誤?看到[readyState爲0,請求可能沒有離開您的瀏覽器](https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest#Properties)。 – Joseph 2013-02-23 16:30:27

+0

注意,'async:true'是默認值,所以不需要指定。 – j08691 2013-02-23 16:31:12

+0

請求URL:http://www.barnesandnoble.com/s關鍵字= 9780201485677&商店=電子書 請求頭 GET http://www.barnesandnoble.com/s?keyword=9780201485677&store=ebook HTTP/1.1 接受: */* Cache-Control:max-age = 0 Referer:http://book.douban.com/subject/1419359/ User-Agent:Mozilla/5.0(Macintosh; Intel Mac OS X 10_7_5)AppleWebKit/537.17 (KHTML,例如Gecko)鉻/ 24.0.1312.57 Safari瀏覽器/ 537.17 查詢字符串參數 關鍵字= 9780201485677&商店=電子書 感謝您的提示,只是檢查,在鉻的網絡選項卡中,我看到上面。仍然不確定是什麼問題。 @JosephtheDreamer – CuiPengFei 2013-02-23 16:49:17

回答

1

的問題很可能在那裏這些URL重定向 - 只有1停留在域:

http://www.barnesandnoble.com/s?keyword=9780735619678&store=ebook #-> 
http://www.barnesandnoble.com/... 

http://www.barnesandnoble.com/s?keyword=9780201485677&store=ebook #-> 
http://search.barnesandnoble.com/... 

你需要包括search.barnesandnoble.com在您的權限:

"permissions": [ 
    "http://www.barnesandnoble.com/", 
    "http://search.barnesandnoble.com/" 
] 
+0

非常感謝,我沒有注意到他們重定向到不同的領域。 – CuiPengFei 2013-02-23 17:11:32