我是第一次使用 AJAX,我正在努力让它工作...... 在我看来,我有一个由我的 Controller 生成的表。 查看(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>";
正如您在最后一行看到的那样,生成的表格有一个按钮,我想在单击该按钮时触发我的 Ajax 函数 (call_supp_bdd)。我想传递给函数2参数,类名和表行对应的对象的id。 这是 vueConsigne.php 中的 ajax 函数:
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();
}
最后这是我的 Ajax 调用的 PHP 文件 (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();
?>
我只是想用这条指令替换它
<?php
echo "sucess";
?>
但它不起作用。
最佳答案
当您加载 jQuery 时,请使用 jquery 的简单语法。不要手动执行。
$.ajax({
url: "test.html",
type: "GET"
}).done(function( response ) {
alert( response );
});
关于javascript - Ajax 简单调用不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31874539/