odus
odus

Reputation: 48

PHP request causes AJAX to reload wrong page

I have a function that calls a HTML code switch when the 'signup' button is clicked. The problem I am having is when I test for a wrong password or wrong email on sign up. I successfully check if the data is correct, but it loads the previous html. Do you know how I can prevent this?

      $(document).ready(function(){
    $("#signupButton").click(function(e){
        e.preventDefault();
        $.ajax({url: "/bookwebsite/html/signup.txt", success: function(result){
            $("body").html(result);
        }});
    });

Above code is the way ajax switches out the HTML body which leads to the 'signup' page.

    //confirm password and confirmed password are the same
      if($signup_password != $signup_password_confirm){
        echo "<font color='red'>Passwords do not match</font>";
        //session_destroy();
        //echo $signup_password . $signup_password_confirm;
        break;
      }

Above code is the PHP that checks that passwords are matching. The commented stuff is things I was just trying.

Thank you!

Upvotes: -1

Views: 68

Answers (1)

Scott Saunders
Scott Saunders

Reputation: 30414

"break" probably doesn't do what you think it does. You probably want "die". Is there other code in your PHP file that might be displayed?

EDIT: "break" is for leaving a loop. Any code after the break statement will continue to run, so if you have a html echoed out after that somewhere, it will appear in the browser. The "die" statement will end all code execution immediately and no code after it will run.

Upvotes: 0

Related Questions