javascript - Putting PHP echo into a button's innerHTML doesn't work -



javascript - Putting PHP echo into a button's innerHTML doesn't work -

i have jquery code this:

$("#erase").click(function(){ $("#erase").attr("disabled", "disabled"); // prevent double-clicking $(this).html("erasing..."); $.post("erase.php", {target: $("#target").val(), criteria: $("#criteria").val()}, function(data){ $(this).html(data); // alter button's caption whatever erase.php echoes. settimeout(function(){ window.location.href = "index.php"; }, 3000); });

the target , criteria both html input tags , button declared button tag. expecting these happen when user clicks button:

button greyed out , text 'erasing...' erase.php called via ajax. erase.php delete row database, , takes several seconds complete. when ajax phone call completed, button text output of erase.php. either "success" or "failure" after 3 seconds, user brought home page.

but in case, step 3 fails. button gets stuck in 'erasing....' (the request does complete, however.)

side note: can't think of improve title question. if can come 1 me. please allow me know in comments. i'd appreciate it.

$(this) within of $.post not 1 had before. seek way

$("#erase").click(function(){ $("#erase").attr("disabled", "disabled"); // prevent double-clicking $(this).html("erasing..."); $this = $(this); $.post("erase.php", {target: $("#target").val(), criteria: $("#criteria").val()}, function(data){ $this.html(data); settimeout(function(){ window.location.href = "index.php"; }, 3000); });

javascript jquery html ajax

Comments

Popular posts from this blog

javascript - I need to update the text of a paragraph by inline edit -

javascript - THREE.js reposition vertices for RingGeometry -

assembly - What is the addressing mode for ld, add, and rjmp instructions? -