duang8642 2015-08-07 09:39 采纳率: 0%
浏览 47

Ajax简单调用不起作用

I'm using AJAX for the first time and I'm struggling to make it work... In my view I have a table generated by my controller. View (vueConsigne.php)

    <tbody>
    <?php echo $tab_plan; ?>
    </tbody>

Controller (control_vueCsn.php):

foreach($lesPlanifs as $laPlanif){
    $tab_plan.= "<tr><td>".$laPlanif->getClass().
            "</td><td>".$laPlanif->get("dateHeureDebut")->format('d-m-Y   H:i:s').
            "</td><td>".$laPlanif->get("dateHeureFin")->format('d-m-Y H:i:s').
            "</td><td>"." ".
            "</td><td>"."Recurrence : ".$val. " " .$unit .
            "</td><td>"."n/c".
            "</td><td><button name=\"suppPlaniSusp\" onclick=\"call_supp_bdd(".$laPlanif->get("id").",".$laPlanif->getClass().")\"><img src=\"../img/close_pop.png\" id=\"suppPlanif\" name=\"suppPlanBtn\" width=\"30\" height=\"30\"></button></td></tr>";

That generated table, as you can see on last line, has a button on which I want to fire my Ajax function (call_supp_bdd) when it's clicked. I want to pass to the function 2 parameters,the class name and the id of the object corresponding to the table line. Here is the ajax function in vueConsigne.php :

    function call_supp_bdd(int,c)
    {

        if (window.XMLHttpRequest)    //  Objet standard
        {
            xmlhttp = new XMLHttpRequest();     //  Firefox, Safari, ...
        }
        else      //  Internet Explorer
        {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }

        xmlhttp.open("GET","../control/suppPlanif.php?q="+int+"&c="+c,true);
        xmlhttp.send();


        }

And finally here is my PHP file called by Ajax (suppPlanif.php) :

    <?php
    /**
    * Created by PhpStorm.
    * User: ymakouf
    * Date: 07/08/2015
    * Time: 10:14
    */
    $q = intval($_GET['q']);
    $c = intval($_GET['c']);
    $cnx = new CNX();
    $dbh = $cnx->connexion();
    $req = $dbh->prepare("DELETE * FROM".$c."WHERE id =".$q);
    $req->execute();

    ?>

I just tried to replace it with just this instruction

    <?php
    echo "sucess";
    ?>

But it doesn't work.

  • 写回答

2条回答 默认 最新

  • douyi3632 2015-08-07 09:43
    关注

    When you're loading jQuery then please use jquery's simple syntax. Dont do it manually.

    $.ajax({
      url: "test.html",
      type: "GET"
    }).done(function( response ) {
      alert( response );
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真