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
, who receives the information has a verification: if (isset($_POST['enviar']))
. If the user clicks the send button, the file continues the action.
But when I’m getting 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 though this one 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?
Pole or pole
HTML
too, please.– Roberto de Campos
First: in AJAX you send the information to
processa.php
, but cites a fileprotocolo.php
. Is that all right? Second: when you make an AJAX request, the button field is not included, as it should only be included by the browser when processing the eventsubmit
form. You will need to review your condition in PHP.– Woss
If sending is a button its value will only be sent if it has the attribute
name
is set, which is not the best way to do it. To find out if a submission of thePOST
better test withif ($_SERVER['REQUEST_METHOD'] == 'POST')
and then test each field individually– Isac
I tested with if ($_SERVER['REQUEST_METHOD'] == 'POST') and it worked. I got the result I expected. I will follow your tips to work in the best way possible. Thank you!
– WebCraft