1
I’m making the POST request by AJAX:
HTML FORM (administration.php):
<form align="center" width="50" name="excluir_documento" id="excluir_documento" onClick='return confirma_excluir_documento()' method="POST">
<input type="text" name="prefixo" id='prefixo' hidden value="DE"></a>
<input type="text" name="sequencial" id='sequencial' hidden value="310"></a>
<input type="text" name="nome_conf" id='nome_conf' hidden value=""></a>
<input type='submit' name='excluir_documento' id='excluir_documento' value='' class='imgExcluir' title='Excluir' ></a>
Javascript (funcoes.js):
function confirma_excluir_documento() {
vex.defaultOptions.className = 'vex-theme-default';
vex.dialog.confirm({
message: 'Você irá excluir o documento. Deseja continuar?',
callback: function(resultado) {
if (resultado) {
$.ajax({
type: "POST",
url: "excluir.php",
data:{
prefixo : $("#prefixo").val(),
sequencial : $("#sequencial").val(),
nome_conf : $("#nome_conf").val(),
excluir_documento : 1
},
success: function (response) {
vex.dialog.alert('response');
}
});
}
}
});
return false;
}
We have sent the php delete.php page:
if(isset($_post['excluir_documento']))...
... if($excluir_resultado){
echo "Documento excluído com sucesso";}
else{
echo "Erro ao excluir";}
The problem I need the return of what happened with the query of the bank, I need to give the result inside the dialog box success: function (response){ vex.dialog.alert('response') ;}
, the problem that the information coming from and the entire page, shaping the dialog box.
How do I get only the part echo "Documento excluído com sucesso";}
?
I have tried in several ways but I could not, I searched the whole afternoon a solution and nothing.
Thanks for the answer, I’ve been looking for this processing of Jquery requests, but I didn’t understand it very well. How will I make that return after I execute and treat the
query
from the bank? Have I triedecho ?><script>return resposta_banco();</script><?php
to call a function with the dialog box, not even the time to execute the function because the page only runs the code and already closes.– Willian Coqueiro
When you run a Mysql query with PHP, it returns a value with the number of lines affected. You can use this as a basis. If delete 1, it returns that a line was affected. 2, "2 affected lines", so on.
– Anderson Nunes
You will return plain text, with ECHO or PRINTF. ;) Javascript you do on client side.
– Anderson Nunes
It worked here, I had even found another solution that gets the same result, but its code gets more objective. Thank you, now a small doubt. How do I submit this request via php class and function up to the delete code?
– Willian Coqueiro
William, try to describe to me better what you want the procedure to do, so I can better guide myself in helping you. What are the steps? What you want the system to do. .
– Anderson Nunes
I got it now, thank you
– Willian Coqueiro
Thanks! *Steps = steps (broker getting in! rs)
– Anderson Nunes
I did what you gave me, but I had information that would only contain in php, I would need this return to display in the msg of Alert. Would global variable solve?
– Willian Coqueiro