Monday, March 25, 2013

jQuery executes error function even on success (200) status

Just lost a couple of hours with this problems.

jQuery was executing an error function regardless the jqXHR status. A little bit about setup:
node.js + Express + Backbone + backbone.paginator + Underscore

After upgrading to Express 3.0 an application that was working without any problems stoped to work. Problem - jQuery was always executing an error function for all ajax requests. After checking the code, googling, reading, debugging, taking a lunch, debugging again and again I saw that I was using res.json() and not res.jsonp() (added in Express 3.x). Change of one line and everything is working back again.

So - if your node.js + express 3.x returns jsonp, please, use res.jsonp() instead of res.json()