Home     |      Learn AJAX     |      Forum     |      Register     |      Submit Resource     |      Submit Article      |      Contact Us

Home AJAX-Tips
 

Error Message Implementation

 

Error messages can be easily customized in an Ajax or JavaScript based application. This simple function will allow developers to be a lot more transparent about their application. This will provide users an idea that the application is actively improved while developers will be immediately informed of the error.


A common error code goes this way:


    $.ajax (function)
    if error: function ()
    showError: Sorry, please contact the administrator


Although this technique is very easy to code, it might have some repercussions on the application especially if Ajax or JavaScript is manually coded. This error function might also work in other user-terminated function.


For example a user presses "escape" or aborts the website before it completely loads. Instead of simply aborting the process, the error function might be thrown. Every time the user ends their transaction in their Ajax based application, the error function is displayed. While this will not have any direct effect on users, the application will look flawed.


Developers have to double check this error function since it can easily discourage users from going back to the application. This might even stop other functions since pressing escape or aborting the webpage will terminate the entire webpage.


The Root of the Error Problem


When you encounter this type of problem, proceed immediately to your XHR. Your XHR might be coded to encompass the entire application. The XHR can be limited in some webpage but it will require too many parameters which will ultimately slow down the application. You should be able to prevent XHR from affecting other functions through coding but the coding could slow down the browsers and affect user experience.


For that reason, it would be a better option to make some changes on the error code rather than pushing the function needed.


Adding Parameters


The best solution to this problem is to create some parameters in the error code. Take note that the error code is currently affecting other functions so they should be left out.


The common code that will prevent user-terminate function from displaying error code goes this way:


if (!userAborted(xhr))
return (function)


The code will basically inform the JavaScript engine that another function will be implemented. The alternative function could be lighter or will prompt the JavaScript engine to continue essential functions.


Ultimately, the error code will go this way:


$.ajax (function)
if error: function ()
if (!userAborted(xhr))
return (function)
showError: Sorry, please contact the administrator


The textStatus and errorThrown Option


There are additional options for Ajax and JavaScript developers to consider. Instead of using (!userAborted(xhr)), developers can choose textStatus or errorThrown. However, using these functions will never become a full parameter for users. XHR will basically ignore these functions and will continue to provide the same error code.


Always be smart when using error function in your Ajax and JavaScript based application. If you're having trouble with implementing these error functions, take a shortcut: there are many frameworks and libraries that can provide a safe error code that will not affect other functions in your application.



Read Next: Ajax Deep Linking through SWFAddress



 

 

Comments



Post Your Comment:

Members Please Login
Your Name:*
e-mail ID:(required for notification)*
Image Verification: 
 
 Subscribe    

Sponsored Links