Author Topic: Ajax Response / Error handling  (Read 3232 times)

gerdriese

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 4
    • View Profile
Ajax Response / Error handling
« on: April 26, 2016, 06:08:38 pm »
Is there any possibility for checking if there was an error during an ajax request (as saving or updating to the server) and showing an error message (message received from the server)? what does the server side has to do? Status Code 500? Json reply? Are there any examples for error handling?
Thanks
« Last Edit: April 26, 2016, 06:14:09 pm by gerdriese »

paramvir

  • Administrator
  • Hero Member
  • *****
  • Posts: 6310
    • View Profile
Re: Ajax Response / Error handling
« Reply #1 on: April 26, 2016, 10:06:00 pm »
Broadly there are 2 type of errors:

1) Unexpected or uncatched errors like 404 or 500 server errors.

dataModel.error callback can be implentend to handle or troubleshoot these kind of errors:

http://paramquery.com/pro/api#option-dataModel-error

If direct Ajax calls are made with jQuery, then $.ajax( { error: function(){} } can be used to handle/ troubleshoot the errors.

http://api.jquery.com/jquery.ajax/

2) catched errors whereby more user friendly messages are returned by the server.

In this case, dataModel.getData( response ) callback can be used to handle/display the error response to user depending upon the format of the error message.

and success callback can be used in case of direct call through jQuery ajax method.

gerdriese

  • Pro Deluxe
  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Ajax Response / Error handling
« Reply #2 on: April 26, 2016, 11:31:56 pm »
Ok, thanks - I'll take a look at the two options! Thanks.