Jquery post - 在PHP包含文件上

问题描述:

Problem:

if on the jQuery I leave only the alert (the commented one on line 8) all goes well.
Question: why the post function is not working for the [x] anchor from the item list?
see photo below for better understanding of the issue. cassetterecorder-museum.com/poze/explanations.jpg

Need:

I Have a list of items on the include file. Each element has an [x] as anchor to remove the respective item from list.

Note:

the jQuery post script below,meant to remove an item from list works in other cases -on the same site (where an include is not involved)
What should I do to make it work?

PHP file contains:
<?php include('includes/inc_menu_right.php');?>

and on the bottom
1. $("**#delete**").click(function(event) {
2.              $.post("includes/ajax-compare.php",
3.              {  id:'check-rem', cid:$cid },
4.              function(data){
5.                  $("#compare").html(data);
6.                  //alert (data);
7.          });
8.  //alert('adada');
9. });

inc_menu_right.php (extract from it)
<ul class="nav navbar-nav navbar-right">
    <li class="dropdown" id="compare">
        <?php
        // incarcare lista
        echo '<a href="#" class="dropdown-toggle" data-toggle="dropdown">
            Lista comparatii <b class="badge">
                ';
                if (isset($_SESSION['cid'])) {
                echo count($_SESSION['cid'])."/4";
                } else echo "0/4";
                echo '
            </b>
        </a>
        <ul class="dropdown-menu">
            ';
            foreach ($_SESSION['cid'] as $car){
            $q='SELECT * FROM car_tb WHERE c_id="'.$car.'"';
            $res=mysql_query($q);
            foreach($dbo->query($q) as $r){
            echo '
            <li><a class="text-center" href="prezentare.php?optiunile='.$r['c_id'].'">'.$r['c_denumire'].'</a> <span class="text-muted"><a href="#" id="**delete**" value="'.$r['c_id'].'" title="Sterge din lista"> [x] </a></span>
            <li>
                ';
                }
                }
                echo '
            <li><a href="comparatie.php">Compara</a></li>
        </ul>';
        ?>
    </li>
</ul>

Thank you!

here is what you would do:

You first want to update your link to have a delete class and set the data-value property to your c_id:

<a href="?delete" class="delete" data-value="'.$r['c_id'].'" title="Sterge din lista"> [x] </a>

Then you want to update your JavaScript to select all ".delete" class elements then retrieve the id from the data-value property using $(this).data('value').

$('.delete').click(function() {
    var params = {
        id:'check-rem',
        cid: $(this).data('value')
    };
    $.post("includes/ajax-compare.php", params, function(data){
        $("#compare").html(data);
    });
    return false;
});