rambo rambo - 1 year ago 55
Node.js Question

how to get the exact status code of the response after doing model.save in backbone js

From the front end, using backbone js I am doing:

.success(function (data) {
console.log("The response is " + JSON.stringify(data));
.error(function (error) {
console.log("The response is " + JSON.stringify(error));

From the server side, the mocked response is

res.status(400).send({message: "Bad request"})

So, I am being able to print the object that is being sent in the res.send method for both 2XX and non-2XX status.
However, I also want to print the exact status (the one being sent in the res.status from the server). Could someone please throw some light on this.

Answer Source

Backbone Ajax requests use jQuery (http://backbonejs.org/#Sync), and your success handler is passed through. Under jqXHR.done (success is deprecated but has the same signature) in the jQuery.ajax docs, you'll see there's 3 parameters.

What you are looking for is:

.success(function (data, statusText, xhr) {
  console.log("The response status code is " + xhr.status);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download