TOOR PIZZZ TOOR PIZZZ - 2 months ago 5
Javascript Question

How to delete a record from database through AJAX using php and also when link is clicked

How to delete a record from database through AJAX using php and also when link is clicked it returns to same page and new list is updated when a link is clicked and id passes through this link ? I am new to AJAX and php

Answer
<a class="delete_data" id="<?php echo $row['id']; ?>">Delete</a>
ajax
$(document).ready(function(){
 $(".delete_data").click(function(){
   var del_id = $(this).attr('id');
   $.ajax({
      type:'POST',
      url:'delete.php',
      data:'delete_id='+del_id,
      success:function(data) {
        if(data) { // Sucess
        } else { // Error }
      }
   });
 });
});
delete.php
$id = $_POST['delete_id'];
$query = "delete from TABLE NAME where ID = $id";
Comments