XMLHttpRequest
to a Server
XMLHttpRequest
object is used to exchange data with a server.
To send a request to a server, we use the open
and send
methods of the XMLHttpRequest
object:
xmlhttp.open( "GET", "AJAX_info.txt", true ); xmlhttp.send( );
Method | Description |
---|---|
|
Specifies the type of request, the URL, and if the request should be handled asynchronously or not.
|
send(string) |
Sends the request off to the server.string : Only used for POST requests |
<script type="text/javascript"> function loadXMLDoc( ) { var xmlhttp; if ( window.XMLHttpRequest ) { // code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp = new XMLHttpRequest( ); } else { // code for IE6, IE5 xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" ); } xmlhttp.onreadystatechange = function( ) { if ( ( xmlhttp.readyState == 4 ) && ( xmlhttp.status == 200 ) ) { document.getElementById("myDiv").innerHTML = xmlhttp.responseText; } } xmlhttp.open( "GET", "AJAX_info.txt", true ); xmlhttp.send( ); } </script> |
“What’s a couple?” I asked my mum. She said, “Two or three.” Which probably explains why her marriage collapsed. — Josie Long |