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.