我有一个网站,向客户销售一些产品。
我希望在将新订单插入 mysql 数据库时弹出警报通知或发出声音。
我搜索了几个小时来找到 ajax 的解决方案,但我是 ajax 实现的新手,现在陷入困境。
我不需要复杂的方法,如果我只能收到通知,那对我来说就可以了。
如果有人给我提示或更详细的引用或指南......非常感谢!
这是 mysql 插入查询:
$result2 = mysqli_query($con, "INSERT into user (emailPrefix,password1,address,address2,orderRnd,dateEmail,name5,phone, date)
VALUES ('$emailPrefix','$password1','$address','$address2','$orderRnd','$dateEmail','$name5','$phone','$date')");
最佳答案
ajax.js
var interval = setInterval( function() {
$.ajax ({
url: "user.php",
success: function(data) {
$("#users").html(data);
}
});
}, 3000);
Above syntax refreshes pages every 3 seconds. You can compare old id of table in every 3 seconds. If new id is there eventually its new inserted values. So popup like below
$result2 = mysqli_query($con, "SELECT id FROM user ORDER BY id ASC");
while($rows = mysqli_fetch_assoc($result2)) {
$NEW_id = $rows["id"];
}
if($NEW_id > $_SESSION["OLD_id"]) {
$_SESSION["destination_OLD"] = $id_flexi;
echo '<audio controls="controls" autoplay>
<source src="beep.wav" type="audio/wav">
<embed src="beep.wav">
Your browser is not supporting audio
</audio>';
}
I have same problem as yours and this is my solutions. Experts recommend other things but I have only this much knowledge.
Good day.
关于javascript - 当新数据插入 mysql 时,ajax 通知警报弹出或发出声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27425262/