Reputation: 1
I have this but is not working which is a mixed of both answers found here (http://stackoverflow.com/questions/10369432/passing-link-with-parameters-with-jquery)... the alert message comes out empty and therefore the delete.php doesn't do anything
Any comments. I am using JQuery 1.8
<!DOCTYPE html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
$(function(){
$(".delete").click(function(e){
var del_id = $(this).attr("id");
e.preventDefault();
$.post("../folder/delete.php", { iid: del_id } ,function(data){
alert(data)
//change the link to deleted
$('#'+del_id).replaceWith('<a href="#" class="delete">Deleted</a>');
});
});
});
</script>
</head>
<body>
<a class="delete" id="1" href='#'>Delete 1</a>
<a class="delete" id="2" href='#'>Delete 2</a>
<a class="delete" id="3" href='#'>Delete 3</a>
</body>
</html>
Delete.php is as follows:
<?php
extract($_POST);
extract($_GET);
if ($del_id!=0){
require_once("../includes/include.php");
deleteItem($del_id);
}
?>
Upvotes: 0
Views: 185
Reputation: 146269
You should change following line
if ($del_id!=0)
with this
if ($iid!=0)
because you are sending
{ iid: del_id } // iid is the variable
from the client side and $iid
will be available in the $_POST
so you can use without extracting
the full $_POST
array
if ($_POST['iid']!=0){...}
Also if you don't echo/print anything from the server side then you can't get back anything in the response.
Upvotes: 1