Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The script given below is using Ajax technology to verify the passcode using sam

ID: 3575299 • Letter: T

Question

The script given below is using Ajax technology to verify the passcode using same php program. Fill in the blanks in the JS program below and html script with appropriate scripts.

<script>

function check(form1){

    var xhttp = new   _________________________;

    xhttp.onreadystatechange = function() {

           if (this.readyState == 4 && this.status == 200) {

                var result = _______________________;

               document.getElementById("result").innerHTML = result;

                if (result.split(" ")[0] =="correct")

                                                document.getElementById("form1").style.display="none";

          }

     };

    xhttp.open("POST", "test2.php", true);

    xhttp.send(new FormData(form1));

    return false;

}

</script>

<body>

<form id= "form1" method =”______”>

<input type="password" name="code" placeholder="type your secret code">

<input type= "submit">

</form>

<p id = "___________"></p>

<!-- more html below -->

</body>
</html>

Explanation / Answer

<script>

function check(form1){

// create http request
var xhttp = new XMLHttpRequest();

xhttp.onreadystatechange = function() {

if (this.readyState == 4 && this.status == 200) {

// get response text into result
var result = xhttp.responseText;

document.getElementById("result").innerHTML = result;

if (result.split(" ")[0] =="correct")

document.getElementById("form1").style.display="none";

}

};

xhttp.open("POST", "test2.php", true);

xhttp.send(new FormData(form1));

return false;

}

</script>

<body>

<form id= "form1" method ="POST">

<input type="password" name="code" placeholder="type your secret code">

<input type= "submit">

</form>

<p id = "result"></p>

<!-- more html below -->

</body>
</html>