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 );
    });
    
    评论

报告相同问题?