JSONP jQuery Ajax Error Handler Callback

Are you using JSONP and jQuery and trying to handle non 200 responses? Getting frustrated that your error handler isn’t firing when it gets a 403, 404, or some other response code? Take a breath and repeat after me.

“There is no error handling in JSONP”

Now that you have fallen into a great despair, let me save you.

Head over to https://github.com/jaubourg/jquery-jsonp to find a good alternative to jQuery’s implementation of JSONP.

The solution was easy to implement and helped me solve the issues I was having with getting 403 and 404 errors on JSONP requests.

jQuery-JSONP is feature rich with

  • error recovery in case of network failure or ill-formed JSON responses,
  • precise control over callback naming and how it is transmitted in the URL,
  • multiple requests with the same callback name running concurrently,
  • two caching mechanisms (browser-based and page based),
  • the possibility to manually abort the request just like any other AJAX request,
  • timeout mechanism.

and compatible with all major browsers

  • Internet Explorer 6+
  • Firefox 2+
  • Chrome 1+
  • Safari 3+
  • Opera 9+

Photo by janet galore