user3722203
user3722203

Reputation: 21

Deletinq record from database using ajax

I have problem with deleting records from database, using ajax and jquery. If i click to button nothing happens. there is my css:

<button class='delete_p' id_p='<?php echo $post_id; ?>'>x</button>"
<script type="text/javascript" src="jquery-1.11.1.js"></script>
<script src="delete_post.js"></script>

and there is ajax that i'm using:

$(document).ready(function(){
$('.delete_p').click(function(){
var del_id = $(this).attr('id_p');
$.ajax({
  type:'POST',
  url:'delete_post.php',
  data:'delete_id='+del_id,
  });
 });
});

and there is delete_post.php that i'm using:

<?php
include 'esas/core/database/connect.php';
$id = $_POST['delete_id'];
$query = "DELETE FROM `status` WHERE `id` = '$id'";
?>

Upvotes: 0

Views: 51

Answers (1)

idmean
idmean

Reputation: 14875

data shouldn't be a string but a JavaScript object:

$.ajax({
  type: 'POST',
  url: 'delete_post.php',
  data: {
     delete_id: del_id
  }
});

Upvotes: 6

Related Questions