PHP reuseable delete row with ajax

My code repeat for everytable. The ajax function and file delete.php repeat everytime I want to delete. Example I have 100 table in mysql I have to make 100 delete.php
=> can I use 1 delete.php for all, same with ajax function as well

Thank you

PHP code,

echo"<td><a href='#' onclick='doConfirm(".$id.")'>Delete</a></td>";

Ajax code

function doConfirm(id)

    {
        var xhttp; 

        var ok = confirm("Are you sure to Delete?")
        if (ok)
        {

          xhttp= new XMLHttpRequest();
           xhttp.onreadystatechange = function() {
            if (xhttp.readyState == 4 && xhttp.status == 200) {
             document.getElementById('show1').innerHTML=xhttp.responseText;
            }


          }

          xhttp.open("GET", "delete.php?id=" + id,true);
           xhttp.send();
        }

}

delete.php

$f0=$_GET['id'];

delete($f0);


Source: mysql

Leave a Reply