Ajax Response Concerns in Font

Generation Data Matrix 2d barcode in Font Ajax Response Concerns

Ajax Response Concerns
ECC200 Generator In None
Using Barcode generator for Font Control to generate, create Data Matrix ECC200 image in Font applications.
www.OnBarcode.com
QR Code Encoder In None
Using Barcode generator for Font Control to generate, create QR-Code image in Font applications.
www.OnBarcode.com
When a user clicks a link on a web site, they expect something to happen. That something might be a loader appearing in the status bar, or the page going blank and then refreshing. Or perhaps a pop-up message appears. In any case, users are quite accustomed to some sort of action occurring when they click something if nothing happens, they tend to get antsy and continue pressing the link, or eventually leave the site entirely. It is not very good, then, that Ajax requests can frequently lead to some serious response time concerns. Let s face it, when you put forth a request to a server, there is going to be some time involved with sending the request, processing it, and then sending
Drawing Data Matrix ECC200 In None
Using Barcode generator for Font Control to generate, create Data Matrix ECC200 image in Font applications.
www.OnBarcode.com
Print Barcode In None
Using Barcode creator for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
CHAPTER 11 CROSS-BROWSER ISSUES
Printing Barcode In None
Using Barcode maker for Font Control to generate, create Barcode image in Font applications.
www.OnBarcode.com
Create USS Code 39 In None
Using Barcode drawer for Font Control to generate, create Code 39 Full ASCII image in Font applications.
www.OnBarcode.com
it back the browser. Now, with basic web-based navigation, the browser has a lot of builtin features to handle said latency features that users are quite used to. Unfortunately, those features do not apply when putting forward an Ajax-based request. When a user clicks an Ajax-enabled link, unless the developer has coded it in themselves, nothing will occur onscreen for the user to understand that something is indeed happening. This can lead to repeated clicking and overall frustration, and it is up to us developers to take care of the situation. A decent way of handling this issue is by placing a loading image into the element toward which a request is heading. If you want to get fancy, an animated GIF loading image is even more user-friendly, as it truly gives the user the impression that something is happening. Consider Figures 11-2 and 11-3, which show an example of loading an image into the screen for the user to view while a request is being processed.
PDF 417 Encoder In None
Using Barcode creator for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
Draw Universal Product Code Version E In None
Using Barcode creation for Font Control to generate, create UPCE image in Font applications.
www.OnBarcode.com
Figure 11-2. If you display a loading image, users will understand that something is happening.
Paint ECC200 In Java
Using Barcode encoder for Java Control to generate, create Data Matrix image in Java applications.
www.OnBarcode.com
Recognizing Data Matrix ECC200 In VS .NET
Using Barcode scanner for .NET framework Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
Figure 11-3. They will therefore stick around until it is done.
Paint Quick Response Code In .NET Framework
Using Barcode creator for Reporting Service Control to generate, create Quick Response Code image in Reporting Service applications.
www.OnBarcode.com
Printing UPC - 13 In Visual Studio .NET
Using Barcode creation for Reporting Service Control to generate, create EAN 13 image in Reporting Service applications.
www.OnBarcode.com
Following is a very simple way to handle the dynamic loading button and subsequent Ajax insertion. Listings 11-3 and 11-4 show the framework for setting up the trick.
Read Barcode In Java
Using Barcode Control SDK for BIRT Control to generate, create, read, scan barcode image in BIRT reports applications.
www.OnBarcode.com
Barcode Maker In None
Using Barcode drawer for Office Word Control to generate, create Barcode image in Word applications.
www.OnBarcode.com
Listing 11-3. The Basic Page Layout That Will Benefit from the Ajax Functionality (sample11_3.html)
Encoding UCC.EAN - 128 In None
Using Barcode maker for Office Word Control to generate, create GTIN - 128 image in Office Word applications.
www.OnBarcode.com
Encode Code 3/9 In None
Using Barcode creator for Microsoft Word Control to generate, create Code-39 image in Microsoft Word applications.
www.OnBarcode.com
<!--Sample11_3.html--> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script src="functions.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="style.css" />
Encoding QR Code 2d Barcode In None
Using Barcode printer for Online Control to generate, create QR image in Online applications.
www.OnBarcode.com
Generating Barcode In C#
Using Barcode generator for .NET Control to generate, create Barcode image in .NET applications.
www.OnBarcode.com
CHAPTER 11 CROSS-BROWSER ISSUES
UPC A Scanner In Java
Using Barcode decoder for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Linear 1D Barcode Maker In .NET Framework
Using Barcode printer for ASP.NET Control to generate, create 1D Barcode image in ASP.NET applications.
www.OnBarcode.com
<title>Sample 11_3</title> </head> <body> <h1>Ajax Response Workaround</h1> <p><a href="#" onclick="loadajax ('test.html','loadpanel')">Click Me!</a></p> <div class="hidden" id="loadpanel"></div> </body> </html>
Listing 11-4. The JavaScript Code That Will Process the Ajax-Based Request and Response (functions.js)
//Function to process an XMLHttpRequest. function loadajax (serverPage, obj){ showLoadMsg ('Loading...'); document.getElementById(obj).style.visibility = "visible"; xmlhttp = getxmlhttp(); xmlhttp.open("GET", serverPage, true); xmlhttp.onreadystatechange = function() { if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { document.getElementById(obj).innerHTML = xmlhttp.responseText; } } xmlhttp.send(null); } //Function to output a loading message. function showLoadMsg (msg){ hidden = document.getElementById('loadpanel'); hidden.innerHTML = '<img src="indicator.gif" alt="" /> ' + msg; }
Now, the key to this example is the hidden class designated by the id loadpanel. This div has its visibility style set to hidden. When the loadajax function is triggered, first the showLoadMsg function is called. This function allows you to assign a message to the loading spinner image to let your users know what is happening. The visibility style of the loadpanel element is then set to visible, and then an Ajax request is made. When the Ajax request finishes executing, it puts the results of the request into the loadpanel element, thus overwriting the loading image and text. This way, the user knows what is going on at all times.
CHAPTER 11 CROSS-BROWSER ISSUES
Degrading JavaScript Gracefully
While the user base that has JavaScript disabled in their web browser is reasonably small (less than 10 percent of users), it is slightly on the rise. Why is it on the rise JavaScript has a bit of a bad rap, and more and more users are savvying up to securing their system. A good amount of users these days have been victims of a virus or two, and have learned that not all browsers are completely secure. How can they fight back Why, by disabling JavaScript (as some would lead you to believe). We as developers know better, but the concept of degrading JavaScript is something you should certainly not take too lightly. There are several notions to take into consideration when going about degrading your JavaScript. A few of them have actually been used in this very book, but I will go into a little bit more detail here on why it works and why you should go about doing it. It should be noted, however, that building a site that degrades nicely for both JavaScriptenabled and JavaScript-disabled users will take longer than one that does not but you can be more certain that the majority of web users will be able to view and use your web project. Perhaps an even more important note revolves around search engine spiders. While users with JavaScript enabled are able to follow Ajax-enabled linking structures, search engine spiders are not. Therefore, if you place a good portion of your content behind Ajax-enabled linking structures, you may be missing out on the benefits of having your web content indexed by a search engine. On a similar note, many sites also implement their navigation using JavaScript meaning that search engines are unable to find these sites pages even if they re not using Ajax. What can you do, then, to degrade your JavaScript so that all can partake of the goodness Well, it is really quite simple. Consider the following block of code, which would work fine if JavaScript were enabled and fail spectacularly if it were disabled:
Copyright © OnBarcode.com . All rights reserved.