| 1 |
/*
|
| 2 |
Code borrowed from: http://safari.oreilly.com/0596101694
|
| 3 |
|
| 4 |
Wrapper function for constructing a request object.
|
| 5 |
Parameters:
|
| 6 |
reqType: The HTTP request type, such as GET or POST.
|
| 7 |
url: The URL of the server program.
|
| 8 |
asynch: Whether to send the request asynchronously or not.
|
| 9 |
*/
|
| 10 |
|
| 11 |
|
| 12 |
function httpRequest(reqType,url,asynch){
|
| 13 |
//Mozilla-based browsers
|
| 14 |
if(window.XMLHttpRequest){
|
| 15 |
request = new XMLHttpRequest( );
|
| 16 |
} else if (window.ActiveXObject){
|
| 17 |
request=new ActiveXObject("Msxml2.XMLHTTP");
|
| 18 |
if (! request){
|
| 19 |
request=new ActiveXObject("Microsoft.XMLHTTP");
|
| 20 |
}
|
| 21 |
}
|
| 22 |
//the request could still be null if neither ActiveXObject
|
| 23 |
//initialization succeeded
|
| 24 |
if(request){
|
| 25 |
initReq(reqType,url,asynch);
|
| 26 |
} else {
|
| 27 |
alert("Your browser does not permit the use of all "+
|
| 28 |
"of this application's features!");
|
| 29 |
}
|
| 30 |
}
|
| 31 |
/* Initialize a request object that is already constructed */
|
| 32 |
function initReq(reqType,url,bool){
|
| 33 |
/* Specify the function that will handle the HTTP response */
|
| 34 |
request.onreadystatechange=null;
|
| 35 |
request.open(reqType,url,bool);
|
| 36 |
request.send(null);
|
| 37 |
}
|
| 38 |
|