javascript - 当新数据插入 mysql 时,ajax 通知警报弹出或发出声音

标签 javascript php jquery ajax

我有一个网站,向客户销售一些产品。

我希望在将新订单插入 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/

相关文章:

javascript - 无法设置 Kendo DropDownList 选定值

javascript - Mousedown 和 mouseup 同时以 Angular 触发

javascript - 解析 request.object.get ("KEY") 总是返回 undefined

javascript - window.body.scrollHeight 在降低高度时不会改变

php - SQLite选择查询具有类似条件的反向

php - 在一页上发送并打印 PHP 数组结果?

php - 如何从 mysql 数组检索数据并在表单中选中复选框

javascript - jQuery fullCalendar + Fancybox 弹出窗口编辑事件

php - jQuery 函数调用 ajax 不起作用/返回任何内容

javascript - 将月份数字转换为名称