Automatically retry jquery ajax calls to listdata.svc after HTTP 500 Errors

I had an issue with a SharePoint page that was making  jQuery ajax calls to get the valid values of a Choice Column on a list. It worked fine  usually but once in a while the ajax calls would return an HTTP 500 Internal Server Error, and the user would see this:

error500

This was usually first thing in the morning, so I assume it happens when SharePoint is warming up.  The ULS Logs gave me no clues.   If the user refreshed the page, the error disappeared.

I found a nice jQuery plugin that will automatically retry  an ajax request after an error  here: https://github.com/johnkpaul/jquery-ajax-retry.

After adding that plugin, I just needed to change one line of code:

return $.ajax(ajaxOptions);

to

return $.ajax(ajaxOptions).retry({ times: 3, statusCodes: [500] });

and that fixed the problem.

Advertisements
This entry was posted in ajax, javascript, jquery and tagged , . Bookmark the permalink.

One Response to Automatically retry jquery ajax calls to listdata.svc after HTTP 500 Errors

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s