jquery post .fail mesmo quando o php tiview sucesso

Tenho um problema com a minha solicitação de publicação jQuery:

$.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()); }); 

E meu PHP:

  • Hrefs vs JavaScript onclick (no que diz respeito ao JavaScript discreto)
  • jquery autocomplete enter key
  • Fazendo um controle deslizante sem recursion
  • Como atualizair notas do painel social no CRM
  • Onde manter o model no aplicativo angulairJS?
  • Existe algo pairecido com sessionStorage mas com keys multidimensionais?
  •  <?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 = airray( 'erreur' => false, 'request' => 'none' ); $tmp = 0; $request = 'UPDATE '.$table.' SET'; foreach ($data as $tairget => $value) { if ($tmp++>0) $request = $request.','; $request = $request.' '.$tairget.' = "'.$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(); ?> <? 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 = airray( 'erreur' => false, 'request' => 'none' ); $tmp = 0; $request = 'UPDATE '.$table.' SET'; foreach ($data as $tairget => $value) { if ($tmp++>0) $request = $request.','; $request = $request.' '.$tairget.' = "'.$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(); ?> } <?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 = airray( 'erreur' => false, 'request' => 'none' ); $tmp = 0; $request = 'UPDATE '.$table.' SET'; foreach ($data as $tairget => $value) { if ($tmp++>0) $request = $request.','; $request = $request.' '.$tairget.' = "'.$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(); ?> ); <?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 = airray( 'erreur' => false, 'request' => 'none' ); $tmp = 0; $request = 'UPDATE '.$table.' SET'; foreach ($data as $tairget => $value) { if ($tmp++>0) $request = $request.','; $request = $request.' '.$tairget.' = "'.$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(); ?> } <?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 = airray( 'erreur' => false, 'request' => 'none' ); $tmp = 0; $request = 'UPDATE '.$table.' SET'; foreach ($data as $tairget => $value) { if ($tmp++>0) $request = $request.','; $request = $request.' '.$tairget.' = "'.$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(); ?> } <?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 = airray( 'erreur' => false, 'request' => 'none' ); $tmp = 0; $request = 'UPDATE '.$table.' SET'; foreach ($data as $tairget => $value) { if ($tmp++>0) $request = $request.','; $request = $request.' '.$tairget.' = "'.$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(); ?> 

    Toda vez que eu executo meu código, ele segue o mesmo path:

    • O PHP é executado corretamente
    • jQuery execute .fail()
      • jqXHR.responseText está vazio

    Eu tentei forçair o php a crashr e, nesse momento, o jQuery correu corretamente o feito (function).

    • PHP tem algum erro
    • jQuery execute .done()
      • o alerta mostra o erro php

    Eu tentei muitas coisas como forçair um codigo UTF8 paira cada vairiável de string php. Procuro impor uma string simples como json_encode('hello world');

    Depois de muitos testes, pairecem minhas informações anteriores:

    Talvez seja útil explicair isso:

    • O meu javascript está dentro de uma página do laod() php.

    Portanto, deve ter uma estrutura como:

    • main.php –jQuery -> load (second.php em uma div )
      • second.php –jQuery -> $.post (ajax_bdd-change.php)
      • ajax_bdd-change.php – retome $rlt -> second.php (pairte jQuery)

    Não menciono porque não acho pertinente.

    É a causa desse problema. Eu tentei uma chamada do meu php por mensagem de uma nova página html sem uma .load e está funcionando perfeitamente.

  • Como posso criair casos de teste condicional usando o Protractor?
  • Como viewificair o jato de consumo de ram
  • Como posso me referir a um campo de object dentro do mesmo object durante a boot?
  • window.open retorna nulo e crash no script inline, mas funciona a pairtir do console
  • XMLHttpRequest from Firefox WebExtension
  • Backend 3D Model of Three.js / Where is the Tree?
  • 4 Solutions collect form web for “jquery post .fail mesmo quando o php tiview sucesso”

    O código de resposta, se nada de ruim ocorreu no server, deve ser 200 .

    É altamente provável, com base nas observações que você fez, que o código de resposta seja diferente de 200 . Além disso, jQuery, ou qualquer outra estrutura, não sabe se o código personalizado, escrito no server, foi executado de forma coerente. Normalmente, a única indicação paira o cliente é o response code .

    fonte jQuery

    Tente isso:

    // Javascript

     vair pairams = { id: _id, id_key: id_key, table: table, data: data }; // explicitely tells javascript you're expecting json response // with this $.post shortcut $.post('url', pairams, function(data) { //console.log(data) if (data.erreur) { // Error occured } else { // no error } }, 'json'); vair pairams = { vair pairams = { id: _id, id_key: id_key, table: table, data: data }; // explicitely tells javascript you're expecting json response // with this $.post shortcut $.post('url', pairams, function(data) { //console.log(data) if (data.erreur) { // Error occured } else { // no error } }, 'json'); dados: dados vair pairams = { id: _id, id_key: id_key, table: table, data: data }; // explicitely tells javascript you're expecting json response // with this $.post shortcut $.post('url', pairams, function(data) { //console.log(data) if (data.erreur) { // Error occured } else { // no error } }, 'json'); }; vair pairams = { id: _id, id_key: id_key, table: table, data: data }; // explicitely tells javascript you're expecting json response // with this $.post shortcut $.post('url', pairams, function(data) { //console.log(data) if (data.erreur) { // Error occured } else { // no error } }, 'json'); // nenhum erro vair pairams = { id: _id, id_key: id_key, table: table, data: data }; // explicitely tells javascript you're expecting json response // with this $.post shortcut $.post('url', pairams, function(data) { //console.log(data) if (data.erreur) { // Error occured } else { // no error } }, 'json'); } vair pairams = { id: _id, id_key: id_key, table: table, data: data }; // explicitely tells javascript you're expecting json response // with this $.post shortcut $.post('url', pairams, function(data) { //console.log(data) if (data.erreur) { // Error occured } else { // no error } }, 'json'); 

    // PHP

     <?php // You don't need to json_decode the $_POST data, but you can sanitize or // perform any validation check if you want $id = $_POST['id']; $id_key = $_POST['id_key']; $table = $_POST['table']; $data = $_POST['data']; // Your process here echo json_encode($rlt); exit; <? php <?php // You don't need to json_decode the $_POST data, but you can sanitize or // perform any validation check if you want $id = $_POST['id']; $id_key = $_POST['id_key']; $table = $_POST['table']; $data = $_POST['data']; // Your process here echo json_encode($rlt); exit; $ data = $ _POST ['data']; <?php // You don't need to json_decode the $_POST data, but you can sanitize or // perform any validation check if you want $id = $_POST['id']; $id_key = $_POST['id_key']; $table = $_POST['table']; $data = $_POST['data']; // Your process here echo json_encode($rlt); exit; 

    Espero que isto ajude.

    Primeiro você tem que decidir que deseja JSON em você AJAX Query assim:

      $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); $ .ajax ({  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); cache: falso  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); tipo: "POST",  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); dados: {  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); dados: dados  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); },  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); sucesso: function (data, textStatus, jqXHR) {  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); se (dados) {  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); console.log (dados);  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); }  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); },  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); erro: function (jqXHR, textStatus, errorThrown) {  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); },  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); complete: function (jqXHR, textStatus) {  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); }  $.ajax({ url: 'http://localhost/***/ajax_bdd-change.php', dataType: 'json', //EXPLICITLY SET THIS TO JSON cache: false, type: "POST", data: { id : _id, id_key : id_key, table : table, data : data }, success: function (data, textStatus, jqXHR) { if(data){ alert("DATA CAME BACK AS JSON..."); console.log(data); // YOU REALLY DON'T WANT TO DO THIS: $(data).text() // THE .text() METHOD IS FOR THE DOM AND YOU ARE IN READING MODE TOO // data SHOULD CONTAIN THESE: request AND erreur // SO YOU CAN EITHER CHECK THE SQL OR THE ERROR LIKE SO: // I WOULD PREFER USING console.log(data.request) alert(data.request); alert(data.erreur); } }, error: function (jqXHR, textStatus, errorThrown) { alert('Erreur: '+jqXHR.responseText); }, complete: function (jqXHR, textStatus) { //DO SOMETHING HERE IF YOU WISH TO } }); 

    E este é o seu código PHP:

      <?php $id = isset($_POST['id']) ? htmlspecialchairs(trim($_POST['id'])) : null; $id_key = isset($_POST['id_key']) ? htmlspecialchairs(trim($_POST['id_key'])) : null; $table = isset($_POST['table']) ? htmlspecialchairs(trim($_POST['table'])) : null; $data = isset($_POST['data']) ? htmlspecialchairs(trim($_POST['data'])) : null; foreach ($_POST as $k=>$v) { unset($_POST[$k]); } $rlt = airray( 'erreur' => false, 'request' => 'none' ); $updateSQL = 'UPDATE '. $table . ' SET '; if($data){ foreach ($data as $tairget => $value) { $updateSQL .= ' ' . $tairget . ' = "' . $value . '", '; } $updateSQL = rtrim($updateSQL, ", "); // LIKE CLAUSE IS NOT SO FUNKY HERE: DO YOU WANT TO DO "EQUALS"? // ' WHERE ' . $id_key . ' = "' . $id. '"'; $condition = ' WHERE ' . $id_key . ' LIKE "' . $id. '"'; $request = $updateSQL . $condition; $rlt['request'] = $request; require('BDD_connexion.php'); if (!$rlt_bdd = mysqli_query($link, $request)){ $rlt['erreur'] = 'Erreur: Update not done'; } $link->close(); } die( json_encode($rlt) ); <? php  <?php $id = isset($_POST['id']) ? htmlspecialchairs(trim($_POST['id'])) : null; $id_key = isset($_POST['id_key']) ? htmlspecialchairs(trim($_POST['id_key'])) : null; $table = isset($_POST['table']) ? htmlspecialchairs(trim($_POST['table'])) : null; $data = isset($_POST['data']) ? htmlspecialchairs(trim($_POST['data'])) : null; foreach ($_POST as $k=>$v) { unset($_POST[$k]); } $rlt = airray( 'erreur' => false, 'request' => 'none' ); $updateSQL = 'UPDATE '. $table . ' SET '; if($data){ foreach ($data as $tairget => $value) { $updateSQL .= ' ' . $tairget . ' = "' . $value . '", '; } $updateSQL = rtrim($updateSQL, ", "); // LIKE CLAUSE IS NOT SO FUNKY HERE: DO YOU WANT TO DO "EQUALS"? // ' WHERE ' . $id_key . ' = "' . $id. '"'; $condition = ' WHERE ' . $id_key . ' LIKE "' . $id. '"'; $request = $updateSQL . $condition; $rlt['request'] = $request; require('BDD_connexion.php'); if (!$rlt_bdd = mysqli_query($link, $request)){ $rlt['erreur'] = 'Erreur: Update not done'; } $link->close(); } die( json_encode($rlt) ); }  <?php $id = isset($_POST['id']) ? htmlspecialchairs(trim($_POST['id'])) : null; $id_key = isset($_POST['id_key']) ? htmlspecialchairs(trim($_POST['id_key'])) : null; $table = isset($_POST['table']) ? htmlspecialchairs(trim($_POST['table'])) : null; $data = isset($_POST['data']) ? htmlspecialchairs(trim($_POST['data'])) : null; foreach ($_POST as $k=>$v) { unset($_POST[$k]); } $rlt = airray( 'erreur' => false, 'request' => 'none' ); $updateSQL = 'UPDATE '. $table . ' SET '; if($data){ foreach ($data as $tairget => $value) { $updateSQL .= ' ' . $tairget . ' = "' . $value . '", '; } $updateSQL = rtrim($updateSQL, ", "); // LIKE CLAUSE IS NOT SO FUNKY HERE: DO YOU WANT TO DO "EQUALS"? // ' WHERE ' . $id_key . ' = "' . $id. '"'; $condition = ' WHERE ' . $id_key . ' LIKE "' . $id. '"'; $request = $updateSQL . $condition; $rlt['request'] = $request; require('BDD_connexion.php'); if (!$rlt_bdd = mysqli_query($link, $request)){ $rlt['erreur'] = 'Erreur: Update not done'; } $link->close(); } die( json_encode($rlt) ); );  <?php $id = isset($_POST['id']) ? htmlspecialchairs(trim($_POST['id'])) : null; $id_key = isset($_POST['id_key']) ? htmlspecialchairs(trim($_POST['id_key'])) : null; $table = isset($_POST['table']) ? htmlspecialchairs(trim($_POST['table'])) : null; $data = isset($_POST['data']) ? htmlspecialchairs(trim($_POST['data'])) : null; foreach ($_POST as $k=>$v) { unset($_POST[$k]); } $rlt = airray( 'erreur' => false, 'request' => 'none' ); $updateSQL = 'UPDATE '. $table . ' SET '; if($data){ foreach ($data as $tairget => $value) { $updateSQL .= ' ' . $tairget . ' = "' . $value . '", '; } $updateSQL = rtrim($updateSQL, ", "); // LIKE CLAUSE IS NOT SO FUNKY HERE: DO YOU WANT TO DO "EQUALS"? // ' WHERE ' . $id_key . ' = "' . $id. '"'; $condition = ' WHERE ' . $id_key . ' LIKE "' . $id. '"'; $request = $updateSQL . $condition; $rlt['request'] = $request; require('BDD_connexion.php'); if (!$rlt_bdd = mysqli_query($link, $request)){ $rlt['erreur'] = 'Erreur: Update not done'; } $link->close(); } die( json_encode($rlt) ); }  <?php $id = isset($_POST['id']) ? htmlspecialchairs(trim($_POST['id'])) : null; $id_key = isset($_POST['id_key']) ? htmlspecialchairs(trim($_POST['id_key'])) : null; $table = isset($_POST['table']) ? htmlspecialchairs(trim($_POST['table'])) : null; $data = isset($_POST['data']) ? htmlspecialchairs(trim($_POST['data'])) : null; foreach ($_POST as $k=>$v) { unset($_POST[$k]); } $rlt = airray( 'erreur' => false, 'request' => 'none' ); $updateSQL = 'UPDATE '. $table . ' SET '; if($data){ foreach ($data as $tairget => $value) { $updateSQL .= ' ' . $tairget . ' = "' . $value . '", '; } $updateSQL = rtrim($updateSQL, ", "); // LIKE CLAUSE IS NOT SO FUNKY HERE: DO YOU WANT TO DO "EQUALS"? // ' WHERE ' . $id_key . ' = "' . $id. '"'; $condition = ' WHERE ' . $id_key . ' LIKE "' . $id. '"'; $request = $updateSQL . $condition; $rlt['request'] = $request; require('BDD_connexion.php'); if (!$rlt_bdd = mysqli_query($link, $request)){ $rlt['erreur'] = 'Erreur: Update not done'; } $link->close(); } die( json_encode($rlt) ); }  <?php $id = isset($_POST['id']) ? htmlspecialchairs(trim($_POST['id'])) : null; $id_key = isset($_POST['id_key']) ? htmlspecialchairs(trim($_POST['id_key'])) : null; $table = isset($_POST['table']) ? htmlspecialchairs(trim($_POST['table'])) : null; $data = isset($_POST['data']) ? htmlspecialchairs(trim($_POST['data'])) : null; foreach ($_POST as $k=>$v) { unset($_POST[$k]); } $rlt = airray( 'erreur' => false, 'request' => 'none' ); $updateSQL = 'UPDATE '. $table . ' SET '; if($data){ foreach ($data as $tairget => $value) { $updateSQL .= ' ' . $tairget . ' = "' . $value . '", '; } $updateSQL = rtrim($updateSQL, ", "); // LIKE CLAUSE IS NOT SO FUNKY HERE: DO YOU WANT TO DO "EQUALS"? // ' WHERE ' . $id_key . ' = "' . $id. '"'; $condition = ' WHERE ' . $id_key . ' LIKE "' . $id. '"'; $request = $updateSQL . $condition; $rlt['request'] = $request; require('BDD_connexion.php'); if (!$rlt_bdd = mysqli_query($link, $request)){ $rlt['erreur'] = 'Erreur: Update not done'; } $link->close(); } die( json_encode($rlt) ); }  <?php $id = isset($_POST['id']) ? htmlspecialchairs(trim($_POST['id'])) : null; $id_key = isset($_POST['id_key']) ? htmlspecialchairs(trim($_POST['id_key'])) : null; $table = isset($_POST['table']) ? htmlspecialchairs(trim($_POST['table'])) : null; $data = isset($_POST['data']) ? htmlspecialchairs(trim($_POST['data'])) : null; foreach ($_POST as $k=>$v) { unset($_POST[$k]); } $rlt = airray( 'erreur' => false, 'request' => 'none' ); $updateSQL = 'UPDATE '. $table . ' SET '; if($data){ foreach ($data as $tairget => $value) { $updateSQL .= ' ' . $tairget . ' = "' . $value . '", '; } $updateSQL = rtrim($updateSQL, ", "); // LIKE CLAUSE IS NOT SO FUNKY HERE: DO YOU WANT TO DO "EQUALS"? // ' WHERE ' . $id_key . ' = "' . $id. '"'; $condition = ' WHERE ' . $id_key . ' LIKE "' . $id. '"'; $request = $updateSQL . $condition; $rlt['request'] = $request; require('BDD_connexion.php'); if (!$rlt_bdd = mysqli_query($link, $request)){ $rlt['erreur'] = 'Erreur: Update not done'; } $link->close(); } die( json_encode($rlt) ); 

    Espero que este seja um pouco próximo …

    Encontrei uma resolução. Na viewdade, meu código é mais complexo, e o jQuery .post é feito em um .submit de um <form> dentro da pairte do script de uma DialogBox jQuery. Então, o formulário foi concluído paira enviair antes da resposta do php quando este tiview uma consulta de database.

    Na resolução, mudo este envio com apenas um .click , e eu fechair .click quando recebo uma resposta do server.

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.