0

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;
});
});
Mike
  • 23,542
  • 14
  • 76
  • 87
Rehmat
  • 4,681
  • 3
  • 22
  • 38
  • You're getting mixed up between server-side code and client-side code. You need to use javascript to send the redirect, not PHP. See: http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-using-jquery – Mike Jul 04 '15 at 20:02
  • Thanks Mike, for your quick response. Can you please guide me a little more? Don't mind as I've just started learning these things. – Rehmat Jul 04 '15 at 20:04
  • you can have have a look here on how to redirect to another page http://stackoverflow.com/questions/503093/how-can-i-make-a-redirect-page-using-jquery – Tasos Jul 04 '15 at 20:08
  • Thanks both of you! It helped. Just echo ""; instead of header redirect and it does the trick! – Rehmat Jul 04 '15 at 20:14

0 Answers0