我正在使用passthru文件来更新由ajax函数触发的数据库。 Ajax是:
$("#updateInventory").live('click', function() {
$('#updateInventory').attr('disabled', 'disabled');
$.ajax({
type: "POST",
url: "updateInventoryExecmws.php",//
dataType: "json",
success: function(data){
update = data.update;
console.log(data);
if (update == true){
alert(data.message);
} else {
$('#message').html(data.saying);
}
}
});
});
和passthru文件是:
<?php
passthru('php /home/bookcell/public_html/testbcos/mbas/updateInventorymws.php >> /home/bookcell/public_html/testbcos/exports/mbas.txt &');
$saying = array('saying' => 'Updating Inventory for today. An email will be sent as soon as the update is finished.');
echo json_encode($saying);
?>
这一切正常,并启动updateInventorymws.php文件。在这里,我需要检查今天是否已完成更新,以及是否已提醒用户并停止执行脚本。除了警报,这一切都正常。以下是此代码:
//inventory already been updated today?
$updatedTodayResult = $conn->query("SELECT * from order_sold where date_sold between NOW() - interval 5 minute and NOW()");
$updatedTodayRows = $updatedTodayResult->num_rows;
if($updatedTodayRows < 1){
$updatedToday = false;
$note = "Updating Inventory for today. An email will be sent as soon as the update is finished.";
}else{
$updatedToday = true;
$note = "Inventory is already updating for today.";
}
if($updatedToday == false){
// run the update here
}
$records = $x;
$to = "myemail@me.com";
$subject = "Update Inventory Report";
$body = $records . " records were successfully updated in today's inventory update!";
mail($to, $subject, $body);
$message = array('message' => $note,
'update' => $updatedToday,
);
}else{
$records1 = 'Someone has attempted to run Update Inventory more than once today. If this problem shouldn\'t occur, please see administrator.';
$to = "myemail@me.com";
$subject = "Update Inventory Report";
$body = $records1;
mail($to, $subject, $body);
$message = array('message' => $note,
'update' => $updatedToday,
);
}
echo json_encode($message);
有没有办法让它从中创建一个警报,以便用户知道更新已经完成了?