AJAX Introduction by Bhanwar Gupta - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

XMLHttpRequest Properties

onreadystatechange

Event handler that fires at each state change

 

You implement your own function that handles this

readyState – current status of request

0 = uninitialized
1 = loading
2 = loaded
3 = interactive (some data has been returned)

This is broken in IE right now

 

4 = complete

status

HTTP Status returned from server: 200 = OK

responseText

String version of data returned from server

responseXML

XML DOM document of data returned

statusText

Status text returned from server

 

00002.jpg

// get an XMLHTTPRequest object
// build a url variable, call it url
// open a connection with the server

/* prepare to receive response, i.e. give it to a function */
// send the request

 

00002.jpg

var myRequest = getXMLHTTPRequest( ); function callAjax( ) // javascript code { var url = “test.php?mike”; myRequest.open( “GET”, url, true ); myRequest.onreadystatechange = responseAjax(); myRequest.send( null ); }

00002.jpg