Test Your JavaScript As You Code

If you are writing JavaScript, you should be testing and linting your code often to catch common mistakes. I enjoy using Sublime Text so I have installed Sublime-JSHint, a Submlime Text 2 plugin that checks my JavaScript code for nasty errors and other coding goodies.

Sublime JSHint in action

It’s super easy to setup so what are you waiting for?!

If you don’t use Sublime Text, find a jshint plugin for your editor over at http://www.jshint.com/install/

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