dongyupen6269 2015-08-04 21:11
浏览 78
已采纳

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!

  • 写回答

1条回答 默认 最新

  • duan0708676887 2015-09-25 09:46
    关注

    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;
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥35 平滑拟合曲线该如何生成
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集