javascript - php ajax mysql从另一个文件发出警报

标签 javascript php jquery ajax

我想从第二页开始提醒第一页,例如我有以下页面

<?php
    $sql = "SELECT table_id, on, off FROM tables"; //just fetching and filling my table with the info
    $stmt = mysqli_prepare($dbc, $sql);
    mysqli_stmt_execute($stmt);
    mysqli_stmt_bind_result($stmt, $table_id, $on, $off);
    while(mysqli_stmt_fetch($stmt)){
?>

<tr>
<td><?php  echo '<button onclick="ShutTime('.$table_id.')" >Disable</button>'; ?><input type="hidden" id="off_<?php echo $table_id; ?>" value="<?php echo $off; ?>"></td> //this  button belongs to the code below 
</tr>   
 }

function ShutTime(table_id, off) { //these datas are sent to another script

    var off = $("#off_" + table_id).val();
    alertify.confirm("Are you sure to disable this ?",
        function(){
               $.post("ajax/deactivateTime.php", { //here
                table_id: table_id,
                off: off,

             },
            function (data, status) {
                  location.reload();
            } 
        );
  }

我在这里处理它们

<?php
 //This scripts receives the data's are sent by the first scripts and processes it
if(isset($_POST['table_id'])  AND isset($_POST['off']))
{
    $table_id = (int) ($_POST['table_id']);
    $off = (int) ($_POST['off']);
    $sql = "UPDATE tables SET status = 0, start_time = DEFAULT WHERE table_id = $table_id";
    $r = mysqli_query($dbc, $sql);
    //after execution I want to alert the above datas into the first script
     $res="Data Passed Successfully"; //as a Test I tried to do like this but no success
     echo json_encode($res);
}
else
{
    exit();
}

一切正常,我想要的只是将 deactivateTime.php 中的数据提醒到我的索引页面,我怎样才能实现这一点?

最佳答案

我解决了我的问题

function ShutTime(table_id, off) { //these datas are sent to another script

    var off = $("#off_" + table_id).val();
    alertify.confirm("Are you sure to disable this ?",
        function(){
               $.post("ajax/deactivateTime.php", { //here
                table_id: table_id,
                off: off,

             },
            function (data, status) {
                  alert(data); //just alerting the data
                  location.reload();
            } 
        );
  }

<?php
 //This scripts receives the data's are sent by the first scripts and processes it
if(isset($_POST['table_id'])  AND isset($_POST['off']))
{
    $table_id = (int) ($_POST['table_id']);
    $off = (int) ($_POST['off']);
    $sql = "UPDATE tables SET status = 0, start_time = DEFAULT WHERE table_id = $table_id";
    $r = mysqli_query($dbc, $sql);
      $res="Data Passed Successfully";  // and junt echoing it as usual 

}

    else
    {
        exit();
    }

关于javascript - php ajax mysql从另一个文件发出警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48678889/

相关文章:

javascript - 如何在 React Native 中将 Firebase 实时数据库数据值增加一个?

php - mysqli_query不起作用。缺少连接?

javascript - 即使使用 'load',div 也不会重新加载更改的内容

php - PyCharm - 社区版是否能够突出显示 php?

javascript - 获取祖先 onclick 属性

jquery - 有没有好的方法来验证 jQuery 代码?

javascript - 调整大小事件处理程序上的响应式 heatmap.js

javascript - 将数据转换为 JSON

javascript - AngularJS(前端)和 Laravel(后端)中 JSON/Arrays 中的 NULL

jquery - 如何停止编写重复的代码