PDA

View Full Version : How to set the jsonp request timeout?



lansea
14 Jul 2010, 6:18 AM
I use Ext.util.JSONP.request() to do a cross domian json requeat, I want to know how to set the timeout, the defaule timeou is 30 sec? it is too long for me ! and I also to know how to set the timeout callback.

thanks

evant
14 Jul 2010, 6:39 AM
Currently it's unsupported. You'd need to modify the request method so that it would run a delayed task to check if the request had succeeded by the timeout duration.

lansea
14 Jul 2010, 7:29 AM
Currently it's unsupported. You'd need to modify the request method so that it would run a delayed task to check if the request had succeeded by the timeout duration.

after I chectout the request is time out, then How can I cancel the request?

evant
14 Jul 2010, 7:45 AM
You'll see it inserts a script tag, remove the script tag from the document.

ITS Telco
26 Jul 2011, 4:53 AM
Hello lansea,

I solve the problem on this way.
First before the request start I set a timer:

alertTimerId = window.setTimeout("timeout_req()", 5000); // for 5 sec

In the function timeout_req I call the callback manually:

Ext.util.JSONP.callback({'error':'timeout'});

For my issue it seems it works. Maybe it is a help for you , too.

best regards
Thomas

wuyahuang
30 Aug 2011, 6:34 AM
Hello ITS Telco.
I use you code.
But Google Chrome show an error
"Uncaught TypeError: Cannot read property 'callback' of null"
and I also found out the method callback() in the file Ext.util.JSONP.js.
how can it be?
Thanks.

ITS Telco
30 Aug 2011, 7:21 AM
Hello wuyahuang,

it is an example for an Ext.util.JSONP.request.
If the timer finished the timeout_req function.

Unfortunately the Ext.util.JSONP.request do not notice this.
So I call in the timeout_req function a callback for the Ext.util.JSONP.request.

Of course the Ext.util.JSONP.request and the callback there must be declared.

Hope it helps.

best regards
Thomas

wuyahuang
30 Aug 2011, 5:46 PM
Hey Thomas.
Thank you for you reply.But I am an newbie about sencha touch.
I don't know how to declared function callback.
can you tell me something about this?

this is my code:
timer = setTimeout("timeout_req()", 5000);
Ext.util.JSONP.request({
url: serverUrl,
callbackKey: 'callback',
scope: this,
params: params,
callback: function(returnObj){
//to do
}
});
function timeout_req(){
Ext.util.JSONP.callback({'error':'timeout'});
}

best regards
wuyahuang

wuyahuang
30 Aug 2011, 8:08 PM
Thank you Thomas.I solve the problem.
This is my code:

var timeOutTimer = window.setTimeout(function (){
console.log('time out.');
}, 5000);
Ext.util.JSONP.request({
url: serverUrl,
callbackKey: 'callback',
scope: this,
params: params,
callback: ajaxRequestCallback(timeOutTimer)
});

function ajaxRequestCallback(timeOutTimer){
return function(returnObj, i){
window.clearTimeout(timeOutTimer);
//to do
}
}