jQuery Ajax Error Handling


/ Published in: jQuery
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.