1
Why This Javascript Doesn’t Work?
Javascript code:
$('#basic_validate').submit(function(e) {
document.getElementById('successmsg').style.display = 'none';
document.getElementById('errormsg').style.display = 'none';
e.preventDefault();
$.ajax({
type: "POST",
url: "../suppliers/resources/controllers/register.php",
async: true,
data: $(this).serialize(),
success: function(data) {
},
complete: function(result){
if(result == true){
//clear inputs
document.getElementById('successmsg').style.display = 'block';
}else{
document.getElementById('errormsg').style.display = 'block';
}
}
});
});
HTML code:
<form class="form-horizontal" method="post" name="frmLogin" id="frmLogin">
//text_inputs
I had an error in this date line: $form.serialize(). In your code there is a }); which I removed so the error was not because of this
– Lucas
@Lucas right, that was one of my questions in the previous comment. I guess whatever you want is
$(this).serialize()
. Corrected in the reply.– Sergio
I updated the main post, it worked but I can’t catch the return. In the case of . php i put true Return when it succeeds and false Return when it gives error @
– Lucas
@Lucas makes
console.log(data);
within the Success function, andconsole.log(result);
inside the complete function. So you know what you receive. What appears in the console?– Sergio
@Lucas makes
console.log(data);
within the Success function, andconsole.log(result);
inside the complete function. So you know what you receive. What appears in the console?– Sergio