【发布时间】:2014-11-29 04:44:03
【问题描述】:
大家好,我遇到了 ajax 函数调用的问题。我尝试访问“delete.php”页面,但它从未被调用。这是我的脚本代码:
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script>
function deleteSpark(sparkID) {
var answer = confirm(sparkID);
//Send the user to the correct page when he presses 'yes / oke'
if(answer==0){
var ajax= $.ajax({ type: "post",
data: {sparkid: sparkID },
url: 'delete.php'
});
ajax.done(function(){
window.location.href = "/sparks.html";
});
ajax.fail(function(){
window.location.href = "/index.html";
})
}
/* OR*/
/* this method after all other code in handler*/
// window.location.href = "/delete.php?sparkid=" + sparkID;
// window.location.href = "/sparks.html";
//Returns false so no events will be executed.
return false;
}
然后我用一个按钮调用它:删除 8
在我的 php 文件“delete.php”中,我这样做:$sparkID = $_POST['sparkid'];
但它永远不会被调用,因为我尝试回应并做一些其他不起作用的事情。有人可以帮帮我吗?
【问题讨论】:
-
confirm方法返回布尔值。做if(answer==false)然后执行。
标签: javascript php jquery ajax