Java Reference
In-Depth Information
“MSXML2.XmlHttp.6.0”,
“MSXML2.XmlHttp.3.0”
];
for (var i = 0; i < versions.length; i++)
{
try
{
var oHttp = new ActiveXObject(versions[i]);
return oHttp;
}
catch (error)
{
//do nothing here
}
}
}
alert(“Your browser doesn't support XMLHttp”);
}
In Chapter 5, you learned that user-defi ned reference type methods are assigned through the
prototype
object. This code follows that rule when writing the
createXmlHttpRequest()
method and the next
method.
Sending the Request
Sending a request to the server involves the
XMLHttpRequest
object's
send()
method. This
send()
is
similar, with the difference being that it doesn't accept arguments.
HttpRequest.prototype.send = function ()
{
this.request.send(null);
}
This version of
send()
is simple in that all you do is call the
XMLHttpRequest
object's
send()
method
and pass it
null
.
The Full Code
Now that the code's been covered, open your text editor and type the following:
function HttpRequest(sUrl, fpCallback)
{
this.request = this.createXmlHttpRequest();
this.request.open(“GET”, sUrl, true);
var tempRequest = this.request;
function request_readystatechange()
{
if (tempRequest.readyState == 4)
{