I IMPLEMENTING BASIC AJAX TECHNIQUES in Font

Paint Data Matrix in Font I IMPLEMENTING BASIC AJAX TECHNIQUES

CHAPTER 4 I IMPLEMENTING BASIC AJAX TECHNIQUES
Creating Data Matrix 2d Barcode In None
Using Barcode creation for Font Control to generate, create Data Matrix ECC200 image in Font applications.
www.OnBarcode.com
PDF-417 2d Barcode Creation In None
Using Barcode drawer for Font Control to generate, create PDF-417 2d barcode image in Font applications.
www.OnBarcode.com
function getIsResourceAvailable() { if(xmlHttp.status == 200) { alert("Successful response"); } else if(xmlHttp.status == 404) { alert("Resource is unavailable"); } else { alert("Unexpected response status: " + xmlHttp.status); } } </script> </head> <body> <h1>Reading Response Headers</h1> <a href="javascript:doHeadRequest('allResponseHeaders', 'readingResponseHeaders.xml');">Read All Response Headers</a> <br/> <a href="javascript:doHeadRequest('lastModified', 'readingResponseHeaders.xml');">Get Last Modified Date</a> <br/> <a href="javascript:doHeadRequest('isResourceAvailable', 'readingResponseHeaders.xml');">Read Available Resource</a> <br/> <a href="javascript:doHeadRequest('isResourceAvailable', 'not-available.xml');">Read Unavailable Resource</a> </body> </html> The first link on the page demonstrates the XMLHttpRequest object s getAllResponseHeaders() method. This method simply retrieves all the response headers as a string. In this example, the response headers are displayed in an alert box. The getAllResponseHeaders() method may be of limited value because it returns all the response headers together as a string. Retrieving a single response header using the getAllResponseHeaders() method requires parsing the returned string to find the single response header in which you re interested. The getResponseHeader method solves this problem by returning the value for a single response header. This method takes a single string argument representing the name of the response header for which the value is desired. This example uses the getResponseHeader method to display the Last-Modified header in an alert box. A real-world application of the getResponseHeader method would be to poll a server resource at certain intervals. The browser would try to update its content from the server resource only if the Last-Modified response header had changed from the last time the server resource was polled.
UCC - 12 Encoder In None
Using Barcode creation for Font Control to generate, create UCC - 12 image in Font applications.
www.OnBarcode.com
Making GS1 - 13 In None
Using Barcode printer for Font Control to generate, create GS1 - 13 image in Font applications.
www.OnBarcode.com
CHAPTER 4 I IMPLEMENTING BASIC AJAX TECHNIQUES
Data Matrix ECC200 Generation In None
Using Barcode printer for Font Control to generate, create Data Matrix 2d barcode image in Font applications.
www.OnBarcode.com
Printing Barcode In None
Using Barcode creator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
The last two links on the page utilize the XMLHttpRequest object s ability to inspect the HTTP status code returned by the server. The XMLHttpRequest object s status method returns the HTTP status code as an integer. A status code of 200 indicates a normal, successful server response. A status code of 500, conversely, indicates that some kind of internal error occurred while the server was attempting to fulfill the request. This example uses the HTTP status code to determine whether a server resource is available. The HTTP status code 404 indicates that the requested resource is not available. The Read Available Resource link on the page requests a simple XML file residing on the server. Because the file is available, the HTTP status code is 200, indicating a successful response. The last link on the page, labeled Read Unavailable Resource, requests a file that does not reside on the server. The server responds with an HTTP status code of 404. The JavaScript event handler inspects the server response, sees the 404 status code, and displays an alert box indicating that the requested resource is not available. Listing 4-4 shows readingResponseHeaders.xml. Listing 4-4. readingResponseHeaders.xml < xml version="1.0" encoding="UTF-8" > <readingResponseHeaders> </readingResponseHeaders> Figure 4-3 shows the result of displaying all the response headers, Figure 4-4 shows the result of reading the Last-Modified header, and Figure 4-5 shows the result of determining whether a Web resource is available.
GS1 - 12 Maker In None
Using Barcode printer for Font Control to generate, create UPC-A Supplement 2 image in Font applications.
www.OnBarcode.com
Paint Bookland EAN In None
Using Barcode generator for Font Control to generate, create Bookland EAN image in Font applications.
www.OnBarcode.com
Figure 4-3. Displaying all the response headers
Data Matrix 2d Barcode Creation In Visual Studio .NET
Using Barcode creation for Visual Studio .NET Control to generate, create Data Matrix 2d barcode image in Visual Studio .NET applications.
www.OnBarcode.com
ECC200 Creation In None
Using Barcode drawer for Online Control to generate, create Data Matrix image in Online applications.
www.OnBarcode.com
CHAPTER 4 I IMPLEMENTING BASIC AJAX TECHNIQUES
Making EAN-13 In None
Using Barcode generator for Software Control to generate, create GS1 - 13 image in Software applications.
www.OnBarcode.com
QR Scanner In None
Using Barcode reader for Software Control to read, scan read, scan image in Software applications.
www.OnBarcode.com
Figure 4-4. Reading a single response header, in this case Last-Modified
Draw Data Matrix 2d Barcode In None
Using Barcode drawer for Excel Control to generate, create DataMatrix image in Microsoft Excel applications.
www.OnBarcode.com
EAN-13 Supplement 5 Decoder In Java
Using Barcode scanner for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Figure 4-5. Determining whether a Web resource is available
Creating Barcode In None
Using Barcode creation for Software Control to generate, create Barcode image in Software applications.
www.OnBarcode.com
Draw European Article Number 13 In VS .NET
Using Barcode generator for Visual Studio .NET Control to generate, create EAN 13 image in .NET framework applications.
www.OnBarcode.com
Dynamically Loading List Boxes
Draw Barcode In Java
Using Barcode generation for Java Control to generate, create Barcode image in Java applications.
www.OnBarcode.com
UPC - 13 Reader In C#
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
www.OnBarcode.com
Web applications are often built using the wizard design philosophy, where each screen asks the user for small bits of input and each successive page s data is built from the previous screen s input. This design pattern is quite useful for certain types of scenarios such as when the user is performing a task that is best completed in a step-by-step, ordered manner. Unfortunately, too many Web applications use this approach because they have to do so. Before Ajax techniques were available, it was difficult if not impossible to update a page dynamically without refreshing 3565005953993bd3170c41194f12907b the entire page when certain parts of the page needed to change based on user input.
Draw UCC.EAN - 128 In Java
Using Barcode encoder for Java Control to generate, create GS1 128 image in Java applications.
www.OnBarcode.com
1D Barcode Printer In .NET
Using Barcode encoder for ASP.NET Control to generate, create 1D Barcode image in ASP.NET applications.
www.OnBarcode.com
CHAPTER 4 I IMPLEMENTING BASIC AJAX TECHNIQUES
One technique to avoid constant page refreshes is to hide data on the page and display it as needed. In the situation where the values in select box B are populated depending on the selected value in select box A, the available values for select box B can be held in hidden select boxes. When the selected value in select box A changes, JavaScript can determine which hidden select should be displayed. That select box can then be made visible and the previous select box hidden. Another variation is to dynamically populate the option elements of select box B with the elements from a hidden list box. These techniques are useful, but their use is limited to scenarios where the changes to the page are restricted to a finite set of choices based on the user s input, and even then the set choices must be relatively small. Say you re building an online classified ads service for automobiles. Potential buyers search for their desired autos by specifying a car s model year, make, and model. To avoid typographical errors on a user s part and reduce the number of dynamic validations required, you ve decided that the model year, make, and model input fields should all be select boxes and that the ads should go back 25 model years. Changing the selection in the model year select box or the manufacturer select box must change the list of available models for that model year and manufacturer. Remember that with each model year the number of available makes changes as new nameplates are introduced and old ones are retired. Also keep in mind that the models available from each manufacturer vary from year to year. With dozens of manufacturers and several models available per manufacturer per model year, the number of combinations of model year, make, and model is staggering. That is far too many combinations to populate the select boxes using JavaScript alone. You can solve this problem easily using Ajax techniques. Each time the selection in the model year or manufacturer select boxes changes, an asynchronous request is sent to the server requesting the list of models available for that particular manufacturer in that particular model year. The server is responsible for determining the list of models for the make and model year requested by the browser. The server will most likely employ a high-speed data lookup component, possibly implemented as a relational database, to perform the actual work of finding the available models. Once the available models are found, the server packages them in an XML file and returns them to the browser. The browser is responsible for parsing the server s XML response and populating the model select box with the available models for the specified make and model year. In this case, notice how well the view of the data is separated from the raw data. The browser is solely responsible for rendering the view of the data. The server is responsible for mining the raw data that must be rendered into a view on the browser. Listing 4-5 demonstrates how you can use Ajax techniques to dynamically create the contents of one select box based on the values of two other list boxes. The example s use case is the classified ads scenario described, where the selected values in a model year select box and a manufacturer select box determine the contents of the model select box. This example uses only four model years, three manufacturers, and four models available from a certain manufacturer for a certain model year. Still, this makes 48 combinations of model year, make, and model! This example would be impossible to do by hiding the list of models for every model year and manufacturer combination and showing the appropriate list depending on the selected manufacturer and model year values.
Copyright © OnBarcode.com . All rights reserved.