I'm currently using a light javascript library to make ajax calls. The library is 'jx'.
And it works fine. But I would like to add a timeout in order to stop the ajax call if there is no response after a certain time. I looked around and it doesn't seems there is a timeout parameter like with jquery...
Is there a way to implement a timeout thanks to a pure javascript? Like this :
timer = setTimeout('function{stop the call}', 20000);
jx.load(url, function(data){
// get the data
clearTimeout(timer);
}
I tried that and it's not working well ... is there an other way to do that? Or to make the ajax call syn
If this is the library you're using, it seems to be possible:
var xhr = jx.init();
var timer = setTimeout(function(){
if(xhr && xhr.abort) xhr.abort();
}, 20000);
jx.load(url, function(data){
clearTimeout(timer);
});