我已經搜索並找不到答案。我有一個循環並等待變量的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