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

How to add Question alert window (something like "Delete row 2?") before deleting the entry from DB?

<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>

You need to use javascript confirm box for that puprose will do your task

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!");
      }
}

You can use the confirm window with a code like

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.");
           }
    });
}

You should add a confirm pop-up before your call:

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

You can use JavaScript's window.confirm() function to display a confirm dialogue to the user and a simple if statement based on their choice, which will either be OK (true) or Cancel (false):

<script type="text/javascript">
function deleteRow(tableName,colName,id, obj){
    if(window.confirm('Delete row ' + id + '?')){
        $.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>

Put an html confirm() before the ajax call.

something like

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

A simple and a very basic interpretation of the confirm box.

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