AJAX
  Home arrow AJAX arrow Page 4 - How to Handle Ajax Errors
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
AJAX

How to Handle Ajax Errors
By: Chrysanthus Forcha
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2009-01-21


    Table of Contents:
  • How to Handle Ajax Errors
  • Server or Transmission Line is not functioning
  • HTTP Status
  • Thread effect of Ajax Request

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    How to Handle Ajax Errors - Thread effect of Ajax Request
    ( Page 4 of 4 )

     

    An Ajax request behaves like a JavaScript thread. While the request is going on, execution of the JavaScript code in the flow of the code carries on, below the statement of the Ajax request. You may want the statements below the Ajax request to use the result (downloaded text) of the Ajax request. The problem is, you may never know when the request will be complete (when the text is completely downloaded). By the time the request is complete, the statements below the request statement would have been executed (without the downloaded text). 

    If it is possible for you to use the Ajax result (downloaded text) in the onreadystatechange method of the Ajax text, to do so. This is the best way to avoid the conflict.  

    If you really must use the Ajax result in the statements below that of the Ajax request, then you should have a while-loop below the Ajax request that will be looping and checking to see if the text has been downloaded, before execution of the statements below the Ajax request continues. The xmlHttp.onreadystatechange method should have a statement to indicate to the while-loop if the required result has been received. 

    Response is taking longer than it should 

    Here I show you haw to handle the situation when the response is taking longer than it should. The thing to do here is to abort the Ajax request when you believe it has taken too long. You will need to determine, however, how long is too long.

    The Ajax object has the method called abort(). This function is used to abort the Ajax request. When the request is aborted, the readyState property is reset to zero and nothing is downloaded; you do not need to worry about the readyState or status properties. The following code segment, typed below the Ajax procedure, aborts the Ajax request after five seconds:

     

    function abortAjax()

    {

    xmlHttp.abort();

    }

     

    setTimeout("abortAjax()", 5000);

     

    Conclusion

    It is not possible to give a clear-cut answer to any of the questions asked in the introduction of the article. There are conditions under which, if you click the Reload button, you will get what you want. There are also conditions when this will not be helpful. Always have the readyState and status property. This will clarify many problems. Do not forget the thread effect of the Ajax request. I showed you in the last section above how to avoid possible conflict.



     
     
    >>> More AJAX Articles          >>> More By Chrysanthus Forcha
     

       

    AJAX ARTICLES

    - PHP AJAX Form Validation
    - Completing a User-Defined CSS Website with P...
    - Create a User-Defined CSS Website with PHP
    - Build A Better Twitter Chat Client Than Cham...
    - Using Division Equations to Make Web Forms S...
    - Using Integer Multiplication to Protect Web ...
    - Using Simple Checksums for Web Form Verifica...
    - Protecting Web Forms with AJAX
    - Using Prototip with AJAX
    - Using Prototip
    - Using the google.load() Method with Google`s...
    - How to Handle Ajax Errors
    - Uncompressing Source Files with Google`s AJA...
    - Using the jQuery Framework with Google`s Aja...
    - Using Google`s Ajax Libraries API




    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek