How could I set up a function using jquery that would allow me to flip the text in a certain container say “#rndbtn” either on success of a .post form or after a certain time like 6000ms.
I am encountering a problem where the request is taking too long so certain browsers will fire off the call again after 60 seconds so I would like it to just flip the text to alert the user it failed after that time rather than tax my server again and again.
$.post("/sendreq", { arg1: arg1, arg2: arg2} ,
function(data,status,xhr) {
if (this.console && typeof console.log != "undefined"){
console.log(status);
console.log(data);
console.log(xhr);
}
if (data == "Error") {
$("#rndbtn").text('Failed');
}
else if (status == "error") {
if (this.console && typeof console.log != "undefined"){
console.log(xhr.status + " " + xhr.statusText + " " +data );
}
$("#rndbtn").text('Failed');
}
else {
if (type!=0) {
if (type!=4) {
$("#rndbtn").text('Sent Successfully');
}
else {
$("#rndbtn").text('Added to List');
}
}
else {
$("#rndbtn").text('Reset Successfully');
}
}
$("#rndbtn").attr("href","");
});
}
1 Answer