最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin9浏览0评论

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

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

Share Improve this question asked Jul 10, 2015 at 5:26 TOOR PIZZZTOOR PIZZZ 721 silver badge9 bronze badges 3
  • follow this url very helpfull stackoverflow./questions/15917833/… – Pankaj Upadhyay Commented Jul 10, 2015 at 5:37
  • I have seen the question and its an answers,But it's not helping out. – TOOR PIZZZ Commented Jul 10, 2015 at 5:57
  • post your code what are using – Pankaj Upadhyay Commented Jul 10, 2015 at 6:05
Add a ment  | 

3 Answers 3

Reset to default 5
<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";

@TOORPIZZZ You can add this to remove the row from the display without refreshing

$(document).ready(function(){
 $(".delete_data").click(function(){
   var del_id = $(this).attr('id');
   var parent = $(this).parent();
   $.ajax({
      type:'POST',
      url:'delete.php',
      data:'delete_id='+del_id,
      success:function(data) {
        if(data) { parent.slideUp(300,function() {
                parent.remove();
        } else { // Error }
      }
   });
 });
});

Make sure you don't have } in a ment by //Error. It took a while until I discovered this.

$(document).ready(function(){
 $(".delete_data").click(function(){
   var del_id = $(this).attr('id');
   var parent = $(this).parent();
   $.ajax({
      type:'POST',
      url:'delete.php',
      data:'delete_id='+del_id,
      success:function(data) {
        if(data) { parent.slideUp(300,function() {
                parent.remove();
        } else { // Error }        <----------------
      }
   });
 });
});

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论