0
I am updating the database. But the json does not return. Can you please help me?
JQUERY FILE
 $(document).ready(function($) {
 // Evento Submit do formulário
 $('#myForm').submit(function() {
  // Captura os dados do formulário
  var myForm = document.getElementById('myForm');
  // Instância o FormData passando como parâmetro o formulário
  var formData = new FormData(myForm);
  // Envia O FormData através da requisição AJAX
  $.ajax({
     url: "update_func.php",
     type: "POST",
     data: formData,
     dataType: "JSON",
     processData: false,  
     contentType: false,
     success: function(retorno){
       if (retorno.status == 1){
        alertigo(retorno.mensagem, {color: 'light-blue'});        
       }else{
        alertigo(retorno.mensagem, {color: 'red'});
        //$('.mensagem').html(retorno.mensagem);
       }
        }
  });
  return false;
 });
});
PHP file
    <?php 
 $panel_atual = "funcionario";
 require "../config.php";
 $retorno= array();
 $id = intval($_POST['id_func']);
 $nome =  $_POST['nome'];
 $naturalidade =  $_POST['naturalidade'];
 $residente =  $_POST['residente'];
 $description =  $_POST['description'];
 $imgvar_func = $_FILES['img']['name']; 
 if (file_exists("img_func/$imgvar_func")) {
  $a = 1;
  while (file_exists("img_func/[$a]$imgvar_func")) {
    $a++;
   }
   $imgvar_func = "[".$a."]".$imgvar_func;
 }
 $result_edit = "UPDATE funcionarios SET naturalidade='$naturalidade', residente='$residente', description = '$description', imagem = '$imgvar_func' WHERE nome='$nome' AND  id='$id'";
 $retorno = mysqli_query($conexao, $result_edit); 
 (move_uploaded_file($_FILES['foto']['tmp_name'], "img_func/".$imgvar_func));
 if($retorno){
  $retorno = array('status' => 1, 'mensagem' => 'REGISTRO INSERIDO COM SUCESSO!');
 }
 else{
  $retorno = array('status' => 0, 'mensagem' => 'ERRO AO INSERIR REGISTRO!');
 }
echo json_encode($retorno);
Put all relevant code, for example form html, page name
– Anderson Henrique
but return any error? I suggest implementing the error block of
$ajaxto see if it is returning error:error: function (xhr, ajaxOptions, thrownError) { ... }– Ricardo Pontual
Possible duplicate of Request ajax is not working
– Ricardo Pontual
Try setting the header header('Content-type: application/json'); echo json_encode($data);
– Felipe
But update return would only be true or false not ?
– Otto