Posted By

vitorbari on 10/18/11


Tagged

ajax javascript jquery


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

jillella
fomigo
spee66


jQuery Ajax Error Handling


 / Published in: jQuery
 

  1. $.ajax({
  2. url: '',
  3. type: 'POST',
  4. dataType: 'json',
  5. data: {},
  6. beforeSend: function(){
  7. $('#load-msg').show();
  8. },
  9. success: function(data) {
  10. $('#load-msg').hide();
  11. if(data.errorStatus){
  12. alert(data.errorMsg || 'An error has occurred');
  13. }else{
  14. // do stuff
  15. }
  16. },
  17. error: function() {
  18. $('#load-msg').hide();
  19. alert('An error has occurred');
  20. }
  21. });

Report this snippet  

You need to login to post a comment.