2015-10-20 53 views
2

我想使一個ajax調用設置異步屬性爲false,但它獲取錯誤,而它在鉻和ie上工作。使用jQuery同步ajax調用不工作在Firefox上

我知道Firefox的高度recomends異步Ajax調用由於用戶體驗的問題,但是我需要得到響應之前繼續做其他的東西,它的確定(和強制性)等待,直到接收到響應..

這裏是工作而不是工作代碼,任何幫助將不勝感激。

data = $.ajax({ 
     url: Common.serverPath + 'recovery/list', 
     crossDomain: true, 
     dataType: 'json', 
     async: true, 
     type: 'GET', 
     contentType: 'application/json', 
     xhrFields: { 
      withCredentials: true 
     } 
    }); 
    setTimeout(function(){ console.log(data.statusText); 
    },3000); 

控制檯:OK

data = $.ajax({ 
     url: Common.serverPath + 'recovery/list', 
     crossDomain: true, 
     dataType: 'json', 
     async: false, 
     type: 'GET', 
     contentType: 'application/json', 
     xhrFields: { 
      withCredentials: true 
     } 
    }); 
    setTimeout(function(){ console.log(data.statusText); }, 
    3000); 

控制檯:InvalidAccessError:一個參數或操作不被底層對象都

+0

[在Ajax中是否正確實現了Ajax?同步問題](http://stackoverflow.com/questions/14272210/has-ajax-been-implemented-correctly-in-firefox-synchronous-issue) – Aprillion

回答

2

我發現支持

Chrome和IE做工精細「跨域請求和數據類型:」jsonp「請求不支持同步操作。」即使它在ie和chrome :) :)