Script to check error message from ajax call

Ajax call captures error message/exception that are thrown on its failure. Below is the way to get that error message.



$.ajax({
                type: "POST",
                url: "Sample/Method",
                dataType:"html",
                success:function(response){
                  //process response object
                    alert("Success!!!");
                },
                error:function (xhr, ajaxOptions, thrownError){                                
                alert(xhr.status); //get error status code                  
                alert(thrownError); //get error message

                alert(xhr.responseText); //get error details
                }    
            });

Below is the breif description of these error terms:
  • xhr.status -- Use this when you have to deal with the error status code, for example session expiration.
  • thrownError -- Use this when you want to display/use error message as it is.
  • xhr.responseText -- Gives you details of error message like cause of error, source of error, etc. Helpful for coders as they come to know cause of error at early stage.




Links for learning JQuery

Hi...found some good links that will be helpful to learn JQuery and also to improve it. Please have a look at them...

  1. http://jqueryui.com
  2. http://coding.smashingmagazine.com/2008/09/16/jquery-examples-and-best-practices/
  3. http://net.tutsplus.com/tutorials/javascript-ajax/14-helpful-jquery-tricks-notes-and-best-practices/


Best practice for using Html Spacing


I was confused with the difference between   and  . Found one good point of UI designing. So sharing with you. Please have a look.

You  might have tried to add spaces between two controllers using either   or  . If you are confused with what to use, here is the difference between two:

  is the character entity reference while   is the numeric entity reference.
They are the same except for the fact that the latter does not need another lookup table to find its actual value.

So, it’s better if you use  . to improve performance!