2
I’m having a problem with a Javascript function. I need to verify the existence of an item in the database and so use a js function with ajax call verificaExistente
. php returns me a Json and in this function I check if there are elements in that return.
The bank’s return is happening as predicted, the problem is the return
. When I call this function within the onclick
of the save button, the value returned is undefined
. Has anyone ever had a similar mistake? I appreciate the help.
Below the code:
$( "#btnSalvar" ).on( 'click', function(){
if( $( "#frmDados" ).valid() !== false ){
if(verificaExistente()) salvar();
else alert("Dados já existentes");
}
});
function verificaExistente(){
$.ajax({
url: "verificaItem.php",
type: 'POST',
dataType: 'json',
cache: false,
data:{
id_tabela : $("#id_tabela").val(),
id_revestimento : $("#id_revestimento").val(),
operador : 'AND'
},
error: function(){
alert('Erro ao Tentar ação.');
},
success: function( retorno ){
if(retorno.dados.length > 0) return false;
return true;
}
});
}
Related: function $.Ajax() return value?
– rray
Yes. The return
retorno
in thesuccess
of$.Ajax()
comes normal. I checked with aconsole.log
and the verification value is actually zero.– rhandrade