Hi all, I have a jquery ajax call below to bitly that on occasion takes over 2 minutes to finish when it fails from a proxy error, although the timeout on the POST is set to 3 sec. Also, some of the successful POSTs take over 7 seconds. Along with timeout I'm using beforeSend with request abort to stop previous request if a new request shows up. I wonder if there is anything else I could do on my end with ajax to drop a any request, successful or not, if it is taking longer than 3 seconds. Much appreciate your time.
var obj = null;
getURL = function(post_data, tryPost, id){
var t3 = new Date().getTime();
console.log("urlSharing ajax start id:", id , "t3:", t3);
obj = $.ajax({
async:false,
type:"POST",
url: bitlyUrl,
data: post_data,
timeout: requestTimeout,
beforeSend: function(){
if(obj != null){
obj.abort();
}
}
})
.done(function(data, textStatus, jqXHR){
if(data){
url_rsp = data.data.url;
var t4 = new Date().getTime();
console.log("urlSharing ajax OK End id:", id, "t4:", t4, "time took:", t4-t3);
}
})
.fail(function(jqXHR, textStatus, errorThrown ){
var err = jqXHR.statusText;
url_rsp = null;
var t4 = new Date().getTime();
console.log("urlSharing ajax Fail End id:", id, "t4:", t4, "time took:", t4-t3);
console.log("ERROR in urlSharing: getURL for ID", id, "post_data:", post_data, "jqXHR:", jqXHR.statusText, "textStatus:", textStatus);
});
return obj;
}