我已经搜索并找不到答案。我有一个循环并等待变量的ajax,当它不等于0时,我想将数据发送到另一个脚本,以便它可以更新数据库,然后重定向到另一个URL。我试过.post和.get,并且无法获取值来更新数据库,但脚本确实重定向。在ajax成功触发php脚本
function updateTrigger(){
$.ajax({
url: "json.trigger.php",
dataType: "json",
cache: false,
success: function(data) {
var scrape_type = data.scrape_type;
var account_id = data.account_id;
if(account_id != 0) {
$.post('update-pending.php', {account_id: account_id, scrape_type: scrape_type});
document.location.href="redirect.com";
}
}
});
}
这是我的update-pending.php,我将变量发送到第一个重定向之前。
$account_id = $_POST['account_id'];
$scrape_type = $_POST['scrape_type'];
$stmt = $con->prepare("UPDATE triggers SET
pending='1'
WHERE account_id = '$account_id' AND scrape_type = '$scrape_type'") or die(mysql_error());
$stmt->execute();
**危险**:您很容易[SQL注入攻击](http://bobby-tables.com/)**,您需要[防守](http://stackoverflow.com/问题/ 60174/best-way-to-prevent-sql -injection-in-php)自己从。 – Quentin 2015-03-13 18:48:17
我会尝试设置'document.location。href ='分配给'$ .post'函数的回调函数。也许重定向正在处理'$ .post'可以做任何事情之前。 – 2015-03-13 18:51:02
即使我注释掉重定向我仍然无法获取数据库更新 – 2015-03-13 18:55:38