Java Reference
In-Depth Information
you would need to do is assign the url property a new value. The same can be said for the callback
function as well.
The createXmlHttpRequest() method remains untouched. This is a helper method and doesn't really
have anything to do with sending the request.
The majority of changes to the module are in the send() method. It is here that the module decides
whether to use asynchronous or synchronous communication. Both types of communication have
very little in common when it comes to making a request; asynchronous communication uses
the onreadystatechange event handler, and synchronous communication allows access to the
XMLHttpRequest object's properties when the request is complete. Therefore, code branching is
required.
HttpRequest.prototype.send = function()
{
this.request.open(“GET”, this.url, this.async);
if (this.async)
{
//more code here
}
this.request.send(null);
if (!this.async)
{
//more code here
}
}
The fi rst line of this method uses the open() method of the XMLHttpRequest object. The async prop-
erty is used as the fi nal parameter of the method. This determines whether or not the XHR object uses
asynchronous communication. Next, an if statement tests to see if this.async is true; if it is, the
asynchronous code will be placed in this if block. Next, the XMLHttpRequest object's send() method
is called, sending the request to the server. The fi nal if statement checks to see whether this.async is
false. If it is, synchronous code is placed within the code block to execute.
HttpRequest.prototype.send = function()
{
this.request.open(“GET”, this.url, this.async);
if (this.async)
{
var tempRequest = this.request;
var fpCallback = this.callBack;
function request_readystatechange()
{
if (tempRequest.readyState == 4)
{
if (tempRequest.status == 200)
{
Search WWH ::




Custom Search