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: