I am writing a basic registration system (for my PHP, JavaScript practice) where I'm facing an annoying bug. I'm submitting the login form via jquery/ajax to send the form data to process.php file and get back the html response from the process.php file to display the errors / success message on login page.
On successful authentication, I want to redirect the user to index.php but in my case, header("Location: index.php"); doesn't redirect the user, instead the index.php page is fetched and displayed on login.php with repeaded navigation and header.
I've tried data-ajax="false" in form but no luck. Meta refresh does the trick for Chrome but in Firefox it doesn't work. Any solution please? My JS file contains this code:
$(document).ready(function() {
$("#regmein").submit(function() {
$.ajax({
type: "POST",
url: 'inc/process.php',
data:$("#regmein").serialize(),
success: function (data) {
// Inserting html into the result div on success
$('#form-result').html(data);
},
error: function(jqXHR, text, error){
// Displaying if there are any errors
$('#form-result').html(error);
}
});
return false;
});
});