12 thoughts on “Login Form: jQuery + PHP + AJAX”

  1. Because of this line of codes
    $(“#myForm”).submit( function() {
    return false;
    });

    my page cannot be directed to the main page. IT stucks at the login page.
    What can I do to direct it back to the mainpage after logging in ?

    1. Yes, you’re right: Those lines of code prevents the page from redirecting.
      Just remove those lines of code and the page will be redirected to the page/link present in the action field of the form tag.

      Hope that clarifies.

      1. However, if i remove that sentence, it works when the user login with the correct pass and username.
        But if they have the wrong username or password “Failed to Login” will not appear on the same page itself.
        Then there will be no point using jquery right?

        1. Try this:

          in login.php you check if login was successful or failed.
          If successful, return 1 else 0

          In my_script.js, there is callback function: check the value returned. Based on that make the decision.
          If it returned 0, then call the method which restricts redirection( noRedirect() ).

          function noRedirect() {
          $(“#myForm”).submit( function() {
          return false;
          });
          }

          Also, when login.php returns 0, using .html attribute display the login failed error message to the user.

  2. when i enter the correct username and password or wrong it does not display “login successfully” or “failed.” It only display the codes in login.php.

    how to solve this issue

    1. @reva, Looks like you copied code from above article? If so, remove the space in the beginning lines of login.php < ?php There shouldn't be any space after < and ? Watch the video and try coding it yourself along with me ..

Leave a Reply to Heidi Teriyaki Cancel reply

Your email address will not be published. Required fields are marked *