I'm having a problem with a JavaScript function. I need to check the existence of an item in the database and so I use a js function with ajax called verificaExistente
. The php returns me a Json and in this function I check if there are elements in that return.
Bank payback is going as planned, the problem is return
. When I call this function inside the% button of the save button, the value returned is onclick
. Has anyone ever had a similar error? Thanks for 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;
}
});
}