Making a Request


In order to make requests, we will always use the AjaxUpdater as our access point. This object provides a layer of separation in our code to keep our XHRs easier to manage and consistent across the application. In this section, we will use this object to make our first engine request and get an idea of why this layer of abstraction is necessary. When we make a request through the AjaxUpdater, we will use a method called Update. The Update method takes three parameters: a method, a service, and an optional callback method. If a callback method is not specified, a default callback will be set in the AjaxUpdater object, which will reset a Boolean called isUpdating to false. This Boolean is set to TRue each time a request is made and set to false within the Ajax object when a response has been received. This is a useful property for checking whether the object is in the process of making a request, and could ultimately be used as a way to add items to a request queue. In addition to the import code from the previous section, we will add code to make a request for the XML file called email.xml from Chapter 3, "The Response." Again, we will make the request through the Update method in the AjaxUpdater object via the GET method, with a callback method named onResponse, which we will create in the next section.

<script type="text/javascript"> function initialize() {     AjaxUpdater.Update("GET", "services/sample.xml", onResponse); } </script> </head> <body onload="javascript:initialize();"> <div ></div> <div ></div> </body> </html>


In order to make sure all of our objects have been imported completely, we need to add our Update request to a method that is fired when the body of the document loads. After the body loads, it will fire the Update method, which, as you can see, passes the parameters that were previously mentioned. Another important part of the request is providing feedback to the user regarding the progress of the request. In order to display the progress, we have a div element with an id of loading. When we receive a response from the Ajax object, we will display a loading message in the element as we did in the first part of the book. After we receive the response from the engine, we will need a place to add it to the page. This place will be the div element, which we gave an id of body. As I am sure you noticed, the concepts in this chapter are all the same as in the first part of the book. The only difference in this second part of the book is that we now have a clean way of executing these tasks, which will make large-scale development much easier to manage and keep our applications much more scalable. Let's move forward by creating the onResponse method I mentioned earlier. This object will contain our first method call to the Ajax object.



Ajax for Web Application Developers
Ajax for Web Application Developers
ISBN: 0672329123
EAN: 2147483647
Year: 2007
Pages: 129
Authors: Kris Hadlock

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net