Download presentation
Presentation is loading. Please wait.
1
Javascript AJAX HTML WEB SERVER Asynchronous
2
AJAX FUNCTIONS
3
MAKES AN HTTP OBJEC T function createRequestObject( ) { var ro; var browser = navigator.appName; if(browser == "Microsoft Internet Explorer") { ro = new ActiveXObject("Microsoft.XMLHTTP"); } else { ro = new XMLHttpRequest(); } return ro; } var http = createRequestObject();
4
SENDS HTTP REQUEST TO WEB SERVER function sndReq() { u = document.getElementById(100).value http.open('get', 'Ajax1.php?v=' + u + "&junk="+Math.random ( ) ); //avoids cache http.onreadystatechange = handleResponse; http.send(null); }
5
HANDLES RESPONSE FROM WEB SERVER function handleResponse() { if( http.readyState == 4 ) //php is done { var response = http.responseText ; document.getElementById(200).innerHTML = response } -- responseText comes from print statements in PHP
6
PHP Program <?php $v = $_GET["v"] ; print $v ; ?> --results are “printed” to responseText in Javascript – all the prints are just concatenated in responseText
7
HTML BODY This is unused Enter… -- field 100 is input to JS; div element 200 is output from JS
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.