2012-07-19 94 views
0

內我有一個對象,我有一個Ajax請求:停止Ajax調用對象

var newsrecentObj = { 
    init: function() { 
     var self = this; 

     self.fetch().done(function(data) { 
      console.dir(data); 
     }).error(function(data) { 
      // stop ajax call 
     }); 
    }, 

    fetch: function() { 
     var self = this; 

     return $.ajax({ 
      url: 'http://url.to/api', 
      timeout: 5000, 
      dataType: 'jsonp' 
     }); 
    } 
} 

var newsrecent = Object.create(); 
newsrecent.init(); 

我想,當發生超時停止請求。但我該怎麼做?

Tnx

回答

0

如果您的請求超時,它由於超時而單獨停止。
順便說一句,你應該處理這個事件,所以看看jQuery ajax文檔中的超時屬性!
http://api.jquery.com/jQuery.ajax/

0

如果您想停止ajax請求,您可以創建對jqxhr對象的引用,並調用.abort方法。