2012-01-10 128 views
0

我在我的應用程序中有一些JSONP,&我想爲它們設置超時。
我該如何設置它?如何將超時設置爲JSONP?

它也許這樣的事情,如果可能的話:)

Ext.util.JSONP.request({ 
url: mhid.dashboard.hbf.controller+'/get_dashboard' 
,method: 'POST' 
,timeout : 50000 // TIMEOUT 
,callbackKey: 'jsonp_callback' 
,params:{ 
    'site' : site 
    ,'fleet' : fleet 
    ,'sn' : sn 
    ,'format' : 'json' 
} 
,callback: function(response, opts) { 
    var obj = response; 
    tpl.overwrite('content', obj); 
    loadMask.hide(); 
} 
,failure: function(response, opts) { 
    alert('Failure'); 
} 

});

在此先感謝

回答

0

您需要實現自己的超時,並執行相應的回調函數:

var failureCallback = function() { 
    // MUST remove the current request, 
    // or it will not dispatch any subsequent new JSONP request 
    // unless you refresh your page 
    delete Ext.util.JSONP.current; 

    alert('Failure'); 
}; 

Ext.util.JSONP.request({..}); // as usual 

var failureTimeoutId = setTimeout(function() { 
    failureCallback(); 
}, 30000); 
  • 丟棄超時如果您的要求成功
  • 丟棄當前請求如果請求具有超時