我有一个jQuery这样的代码:把PHP呼应成一个按钮的innerHTML不起作用
$("#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); // Change the button's caption to whatever erase.php echoes.
setTimeout(function(){
window.location.href = "index.php";
}, 3000);
});
的target
和criteria
都是HTML input
标签和按钮被声明为button
标签。 我期待,当用户点击这些按钮会发生:
- 按钮将显示为灰色和它的文本会说“擦除......”
erase.php
将通过AJAX调用。erase.php
将从数据库中删除一行,并需要几秒钟才能完成。- 当AJAX调用完成时,按钮文本将是
erase.php
的输出。这将是“成功”或“失败” - 3秒钟后,用户将被带回主页。
但在我的情况下,第3步失败。按钮陷在“擦除......”(请求确实完整的,但是。)
附注:我真的不能相信对于这个问题更好的称号。如果你能为我提出一个。请在评论中告诉我。我会很感激。
控制台中的任何错误消息? – Gowri 2014-10-08 03:50:02
@Gowri控制台中没有错误。 – starleaf1 2014-10-08 03:52:17
提供警报消息以检查响应。 'alert(data);'在$(this).html(data)之前; ' – Gowri 2014-10-08 03:54:01