Variables $ _POST are not defined after consultation with ajax method

2

I'm having a problem using "FormData" objects, it happens that when sending the data with the ajax method (from jquery) the variables $ _POST are not defined in the .php file; honestly I do not know where the fault is, because when you pass a json everything works normally.

Javascript code:

$( "body" ).on("click","#boton_guardar_cambios_entrada",function(e){

    var data = new FormData();
    data.append('autor','Chris');   


     $.ajax(
     {
        url: "editar_entrada.php",
        type: "POST",
        data: data,
        processData: false,
        contentType: false,
        success: function(json){
            alert(json.hello);

        }});//fin de ajax   
   });

And in the file "edit_entrada.php":

<?php

  $jsondata = array();
  $autor=$_POST['autor'];
  $jsondata["hello"]=$autor;
  header('Content-type: application/json; charset=utf-8');
  echo json_encode($jsondata, JSON_FORCE_OBJECT);

?>
    
asked by JeFNDZ 05.10.2018 в 18:53
source

1 answer

0

within your main function you can try this

const postData = {author:'Chris'};

$.post(url,postData,function(response){
  console.log(response);
});
    
answered by 02.11.2018 в 00:17