简体   繁体   中英

How to load forms using ajax

I'm making a simple login and register form using ajax This is my code:

function loadRegistrationForm() {
    var xhttp = new XMLHttpRequest();
    xhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
            document.getElementById("container").innerHTML =
            this.responseText;
        }
    };
    xhttp.open("GET", "registrationform.php", true);
    xhttp.send();
}

.

<div id="container">
  --->LOGIN FORM
  <a onclick="loadRegistrationForm">Register?</a>
</div>

but whenever I click the link the registration form will only flash for a second then it gets back to the login form. What am I doing wrong?

use

onclick="loadRegistrationForm()"

instead of

onclick="loadRegistrationForm"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM