2012-12-11 26 views
1

試圖用jQuery構建一個簡單的AJAX請求。下面是咖啡腳本:jquery ajax請求失敗,錯誤爲chrome(with async:false),但在FF中工作

$('#ad_id_string').blur(function() { 
    var self, idString, adURL; 
    self = $(this); 
    if (self.val() != "") { 
     idString = self.val(); 
     adURL = "/advertisements/" + idString; 
     $.ajax({ 
     url: adURL, 
     type: "GET", 
     dataType: "json", 
     data: "", 
     async: false, 
     contentType: "application/json", 
     success: function(response, textStatus, jqXHR) { 
      console.log(response); 
     }, 
     error: function(jqXHR, textStatus, errorThrown) { 
      console.log("Failed - " + textStatus + " : " + errorThrown); 
     } 
     }); 
    } 
}); 

Firefox執行請求沒有問題,JSON按預期返回。但是Chrome拒絕發送請求。相反,它給出了這樣的錯誤:NETWORK_ERR: XMLHttpRequest Exception 101

我試過設置async:true而不是false,以及去除async參數都在一起。這隻會導致chrome在發送之前使請求失敗,而沒有任何錯誤。我的Q/A人員將在Chrome或Safari中測試此功能,因此需要在這些瀏覽器中工作。

回答

0

看起來這有一些東西與我的Chrome版本(23.0.1271.97),以及相關網址。我使用的是Rails,所以我點擊了http://localhost:3000,而且Chrome瀏覽器遇到了通過端口號傳遞AJAX請求的問題。

相關問題