[英]JSON Delete Table Row
我正在嘗試使用JSON刪除一行數據,但是當我提示確認對話框時,我的javascript函數無法正常運行,如下所示:
<script type="text/javascript">
$().ready(function() {
$("a.delete").click(function() {
$.ajax({
type: "POST", contentType: "application/json; charset=utf-8", url: this.href, data: "{}", dataType: "json",
success: function(msg) {
if (msg.status == "ok") {
$("tr#" + msg.id).hide();
}
else {
alert(msg.exception);
}
}
});
return false;
});
});
</script>
上面的工作絕對正常,但是我將以下內容放入其中:
<script type="text/javascript">
$().ready(function() {
$("a.delete").click(function() {
if (!confirm("Are you sure you want to delete this?")) return false;
$.ajax({
type: "POST", contentType: "application/json; charset=utf-8", url: this.href, data: "{}", dataType: "json",
success: function(msg) {
if (msg.status == "ok") {
$("tr#" + msg.id).hide();
}
else {
alert(msg.exception);
}
}
});
return false;
});
});
</script>
這確實執行了刪除操作,但是並沒有隱藏表行,這使我認為它尚未被刪除。 有任何想法嗎?
嘗試這個:
<script type="text/javascript">
$().ready(function() {
$("a.delete").click(function() {
if (confirm("Are you sure you want to delete this?")){
$.ajax({
type: "POST", contentType: "application/json; charset=utf-8", url: this.href, data: "{}", dataType: "json",
success: function(msg) {
if (msg.status == "ok") {
$("tr#" + msg.id).hide();
}
else {
alert(msg.exception);
}
}
});
}
return false;
});
});
</script>
希望這對你有用...
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.