weixin_33717117 2017-07-03 13:57 采纳率: 0%
浏览 29

用Ajax和PHP刷新

Intro:

last Monday my webserver(Debian 8, Postgres 9.3, Apache 2 and PHP 5) have crashed :( The good new is I have backup of the data :)

From then I was installing the new server with this enviroiment: Debian 8, Postgrest 9.4, Apache 2, PHP 5

Today the server it's working fine and I have restored the data on the Postgres tables.

In the website I have a page with a table that I load data of Postgres query.

I select row with checkbox and I click a button to update the select registers in the database using Jquery + Ajax + PHP

Problem:

From I have re-installed the new server when I want update registers I don't show correctly. I have reload to page by hand to see correctly the updates.

For example: I select 8 registers, click the button to change a field, after it's executed the update.php only it's updated 6 and 2 not :( This happen at times, it's posible I select 8 and 5 good... or whatever

I use this code to reload the page after Ajax Request:

$.ajax({
        url:"updateEstado.php",
        type:"POST",
        data:{"estado": inputvalue, "id_fichaje": value, "saldo": arraySaldo[key]},
        dataType:"text",
        success:function(data){
        $('#canviestat').modal('hide');                     //Close window modal
        $('#tableprod').bootstrapTable('uncheckAll');   // Unchecked all checkboxes
        window.location.reload();                               // Recargar página
 }

});

I try a lot of things. Window.location.reload(true) -> without cache, also to redirect to initial page...

The php code:

<?php
        header('Content-type: application/json');

        session_start();

        if(isset($_SESSION['username']) and $_SESSION['username'] != ''){

                include("db_tools.php");
                include("functions.php");

                $conn = dbConnect("localhost", "5432", "-", "-", "-");

                $estado = $_POST['estado'];
                $estado = Estado($estado);

                $id_fichaje = $_POST['id_fichaje'];
                $saldo = $_POST['saldo'];

                $username = $_SESSION['username'];

                $query = "UPDATE produccion.estado SET usuario='{$username}', estado='{$estado}', fecha_mod=now() WHERE id_fichaje = '{$id_fichaje}'";

                $result = pg_query($conn, $query);

                pg_close($conn);

        } else{
            ?>
            <br>
        <br>
        <div class="row">
              <div class="text-center">
                  <p class='errorLogin'>La sessió no està activa, si us plau login <a href="login.php">aquí</a></p>
              </div>
        </div>
<?php
        }?>

It show this error in debug console in the register aren't upload correctly:

jquery.min.js:4 XHR failed loading: POST

Screenshot of debug network console:

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 echarts动画效果失效的问题。官网下载的例子。
    • ¥60 许可证msc licensing软件报错显示已有相同版本软件,但是下一步显示无法读取日志目录。
    • ¥15 Attention is all you need 的代码运行
    • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
    • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
    • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
    • ¥30 关于<main>标签页面跳转的问题
    • ¥80 部署运行web自动化项目
    • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
    • ¥30 VMware 云桌面水印如何添加