0% found this document useful (0 votes)
26 views

AJAX JavaScript

This document contains the code for an AJAX form that uses JavaScript to send a username input to a PHP file called check.php without reloading the page. When the username is entered or the button is clicked, an XMLHttpRequest object is created to send a POST request with the username parameter to check.php. The response is then displayed in the result div without refreshing the page.

Uploaded by

mr25000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views

AJAX JavaScript

This document contains the code for an AJAX form that uses JavaScript to send a username input to a PHP file called check.php without reloading the page. When the username is entered or the button is clicked, an XMLHttpRequest object is created to send a POST request with the username parameter to check.php. The response is then displayed in the result div without refreshing the page.

Uploaded by

mr25000
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

C:\Users\zeus\Downloads\ajax-source-files\form.

html Saturday, October 10, 2015 12:33 PM

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Ajax Form</title>
<script>
function checkServer() {
var ajaxrequest;
var username = document.getElementById("username").value;
if (window.XMLHttpRequest) {
ajaxrequest = new XMLHttpRequest();
} else {
ajaxrequest = new ActiveXObject("Microsoft.XMLHTTP"); /// Older Browsers
}
ajaxrequest.onreadystatechange = function() {
//console.log(ajaxrequest);
if (ajaxrequest.readyState == 4 && ajaxrequest.status == 200) {
document.getElementById("result").innerHTML = ajaxrequest.responseText;
}
}
ajaxrequest.open("POST", "check.php", true);
ajaxrequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
ajaxrequest.send("name=" + username);
}
</script>
</head>
<body>
<input type='text' id='username' onkeyup="checkServer()">
<button type='button' onclick="checkServer()">Check Content</button>
<div id='result'></div>
</body>
</html>

-1-

You might also like