Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JavaScript Ajax GET Demo</title> <script> function displayFullName() { // Creating the XMLHttpRequest object var request = new XMLHttpRequest(); // Instantiating the request object request.open("GET", "/examples/php/greet.php?fname=John&lname=Clark"); // Defining event listener for readystatechange event request.onreadystatechange = function() { // Check if the request is compete and was successful if(this.readyState === 4 && this.status === 200) { // Inserting the response from server into an HTML element document.getElementById("result").innerHTML = this.responseText; } }; // Sending the request to the server request.send(); } </script> </head> <body> <div id="result"> <p>Content of the result DIV box will be replaced by the server response</p> </div> <button type="button" onclick="displayFullName()">Display Full Name</button> </body> </html>