if (isset ($ _ POST ['send'])) does not work with Ajax

0

I am sending information to another page via Ajax:

<script type="text/javascript">
  //Função para enviar as informações para o arquivos processa.php 
  //via Ajax
  function envia(x){


      jQuery('#form_protocolo_' + x).submit(function(){
        var dados = jQuery( this ).serialize();

        alert(dados);

        jQuery.ajax({
          type: "POST",
          url:  "processa.php",
          data: dados,
          success: function( data )
          {
            document.getElementById('resultado').innerHTML = ( data );
          },
          error: function(data, textStatus){
            alert( textStatus );
          },

        });
        return false;
      });
  }
</script>

However, my file protocolo.php , which receives the information has a check: if (isset($_POST['enviar'])) . If the user clicks the submit button, the file continues the action.

But when I am having the answer in success: function( data ) it behaves as if the user had not pressed the Send button, returning me Você não clicou no botão enviar! , even if he clicked on it.

if (isset($_POST['enviar'])){

  //Executa a ação

} else {

  echo "Você não clicou no botão enviar!";

}

What can it be?

    
asked by anonymous 18.07.2017 / 14:34

1 answer

2

You are looking for the "Send" index in the Global POST array, but this index has not been defined at any time, is this in your HTMl as the name of one of the fields on your form? Make an Isset of any of the form fields and remember to assign a name to all of them and make Isset from the Name and not the ID or other attribute.

    
18.07.2017 / 14:50