在从DB中删除行之前添加警报窗口

时间:2012-05-25 08:16:01

标签: php javascript sql ajax

如何在从DB中删除条目之前添加问题警告窗口(类似“删除第2行?”)?

<script type="text/javascript">
function deleteRow(tableName,colName,id, obj){
    $.ajax({
           type: "POST",
           url: "callpage.php?page=tables/delete.php",
           data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id,
           success: function(msg){
             if(msg === '1'){
                obj = $(obj).parents('tr');
                $(obj).slideUp().remove();
             }
             else
                 alert("Error.");
           }
    });
}
</script>

6 个答案:

答案 0 :(得分:2)

您可以使用JavaScript的window.confirm()函数向用户显示确认对话框,并根据他们的选择显示简单的if语句,该语句可以是 OK ({{ 1}})或取消true):

false

答案 1 :(得分:0)

你需要使用javascript confirm box,因为puprose将完成你的任务

function deleteRow(tableName,colName,id, obj){ 
    var r=confirm("you need to delete row from" + tableName + "having id :" +id );
    if (r==true)
      {
           $.ajax({
                   type: "POST",
                   url: "callpage.php?page=tables/delete.php",
                   data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id,
                   success: function(msg){
                     if(msg === '1'){
                        obj = $(obj).parents('tr');
                        $(obj).slideUp().remove();
                     }
                     else
                         alert("Error.");
                   }
            });

       }
    else
      {
      alert("You pressed Cancel!");
      }
}

答案 2 :(得分:0)

您可以使用带有

等代码的确认窗口
if (confirm('Want to delete row XY ? ')) {
    $.ajax({
           type: "POST",
           url: "callpage.php?page=tables/delete.php",
           data: "tableName=" + tableName + "&colName=" + colName + "&id=" + id,
           success: function(msg){
             if(msg === '1'){
                obj = $(obj).parents('tr');
                $(obj).slideUp().remove();
             }
             else
                 alert("Error.");
           }
    });
}

答案 3 :(得分:0)

您应该在通话前添加确认弹出窗口:

function deleteRow(tableName, colName, id, obj) {
  if(confirm("Are you sure to delete this row?")) {
    // ...
  }
}

答案 4 :(得分:0)

在ajax调用之前放置一个html confirm()。

类似

var r=confirm("Do you want to delete?")
if (r==true)
{
  //call the delete function
}

答案 5 :(得分:0)

对确认框的简单和非常基本的解释。

var r=confirm("Press a button");
if (r==true)
{
  alert("You pressed OK!");
}
else
{
  alert("You pressed Cancel!");
}