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()

1 comment:

David Smith said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a Front end developer learn from JQuery Training in Chennai . or learn thru JQuery Training . or learn thru ES6 Online Training. Nowadays JavaScript has tons of job opportunities on various vertical industry.