Step 4. Define the response actions when the server’s response is received:code for modern browsers
Define the response actions when the server’s response is received:code for modern browsers
Define the request that is sent “behind the scenes”The request will send theuserNamevalue tovalida%on.php,which can access it using $_GET['userName'].code for modern browsers
Send the requestAJAX for partial update of the pageDONE!!<script>function validation(){varxmlhttp;if (window.XMLHttpRequest){ // code for modern browsersxmlhttp= newXMLHttpRequest();}else{// code for old IE browsersxmlhttp= newActiveXObject("Microsoft.XMLHTTP");}xmlhttp.onreadystatechange=function(){if (xmlhttp.readyState==4&&xmlhttp.status==200){document.getElementById("responseMessage").innerHTML=xmlhttp.responseText;}}a= document.getElementById("userName");xmlhttp.open("GET","validation.php?userName="+a.value, true);}</script>The Javascript code in example.html
PHP code on the serverOutputgenerated byvalida1on.phpNow, create validation.phpfor responding to the AJAX request.