I have a problem with my post jQuery query:
$.post( 'http://localhost/***/ajax_bdd-change.php', {'id': _id, 'id_key': id_key, 'table': table, 'data': data}) .fail(function(jqXHR, textStatus, errorThrown){ alert('Erreur: '+jqXHR.responseText); }) .done(function(data){ alert($(data).text()); });
And my PHP:
<?php $id = json_decode($_POST['id']); $id_key = json_decode($_POST['id_key']); $table = json_decode($_POST['table']); $data = json_decode($_POST['data']); foreach ($_POST as $k=>$v) { unset($_POST[$k]); } $rlt = array( 'erreur' => false, 'request' => 'none' ); $tmp = 0; $request = 'UPDATE '.$table.' SET'; foreach ($data as $target => $value) { if ($tmp++>0) $request = $request.','; $request = $request.' '.$target.' = "'.$value.'"'; } $request = $request.' WHERE '.$id_key.' LIKE "'.$id.'"'; $rlt['request'] = $request; require('BDD_connexion.php'); if (!$rlt_bdd = mysqli_query($link, $request)){ $rlt['erreur'] = 'Erreur: Update not done'; } $link->close(); echo json_encode($rlt); exit(); ?>
Every time I run my code, it goes the same way:
- PHP is executed correctly.
- running jQuery
.fail()- jqXHR.responseText is empty
I am trying to get php to crash and while jQuery is running the executed (function) correctly.
- PHP has some error.
- Running jQuery
.done()
I tried many things how to force UTF8 encoding for every php string variable. I am even trying to overlay a simple string like json_encode('hello world');
After many tests, it seems to me that my previous information:
It may be useful to explain that:
- my javascript is inside the
laod() php page.
Therefore, it should have such a structure as:
- main.php --jQuery ->
load (second.php in div )- second.php --jQuery →
$.post (ajax_bdd-change.php) - ajax_bdd-change.php --return
$rlt rlt → second.php (part of jQuery)
I do not mention this because I do not find it suitable.
It is the cause of this problem. I tried calling my php by mail from a new html page without .load , and it works fine.
source share