0

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); 
    } 
?>
4

1 回答 1

1

您应该更改以下行

if ($del_id!=0)

有了这个

if ($iid!=0)

因为你要发送

{ iid: del_id } // iid is the variable

从客户端并且$iid将在 中可用,$_POST因此您可以在没有extracting完整$_POST阵列的情况下使用

if ($_POST['iid']!=0){...}

此外,如果您不从服务器端回显/打印任何内容,那么您将无法在响应中取回任何内容。

于 2012-12-14T19:50:18.263 回答