Reputation: 1668
I have a simple function that handles submission of row data (one submission per loop).
I will not go into to much detail for what the function is mainly used for but a here is a short summary:
I ahve a lot of data that I loop through and on every loop I call upload()
function that has an ajax function. Ajax submits the data as a post and then on success calls insert()
function that continues trhough the loop and calls upload()
again untill all the data is processed.
upload: function( data ){
var obj = this;
if( data.post_code && data.post_code.length > 0 ){
if( ajax_insert ){
ajax_insert.abort();
}
try{
ajax_insert = $.ajax({
type : 'POST',
url : '/submission/my-function?ajax',
data : $.param( data ),
success : function( response ) {
obj.insert();
},
error: function(msg){
setInterval(function(){
obj.insert();
}, 2000);
}
});
}catch(err){
ajax_insert.abort();
obj.insert();
}
}else{
this.insert();
}
}
The problem that some clients experience is a stop of submission after some time (some after 60 submits some after 100+). I am not sure if this is because of a slow internet connection but what I noticed using the console on firebug is that when the submission stops in the console it is still showing that Ajax is trying su submit but never completes. And there are no javascript errors shown.
Is there a way to pick up if Ajax is taking to long to complete a submission (lets say it's stuck for almost 5min) and use the .abort()
to try again?
Thanks.
Upvotes: 0
Views: 430
Reputation: 2915
you could use..
timeout: 10000, //time in milliseconds.
This would at least catch a stalled script.
Upvotes: 1