I can't figure it out, i have a form submitted by ajax and the ajax code always return false even if the form values doesn't meet the requirement. Also the function that should happend in the form action php file when the form is correct doesn't happend so it doesnt matter if i fill in the required fields or not, or if i fill them right or wrong the ajax will call it success and the php action wont work{even if the form is correct!}
Form :
<form method="POST" onsubmit="return loginSubmit(this)">
<input type="text" name="username" placeholder="username"></br>
<input type="password" name="password" placeholder="password"></br>
<button type="submit" name="submit">login</button>
</form>
Function :
function loginSubmit(element){
var values = $(element).serialize();
$.ajax({
type: 'post',
url: 'assets/login.inc.php',
data: values,
success: function(data){
alert('success');
}
});
return false;
}
Form Action{php} :
it's kind of long and i dont want this post to look like a mess so i'm just writing the way i pull the data from the form, the php code works fine when i submit the form without ajax.
$username = mysqli_real_escape_string($conn, $_POST['username']);
$password = mysqli_real_escape_string($conn, $_POST['password']);