如何在 backbone js 中执行 model.save 后获取响应的确切状态代码
how to get the exact status code of the response after doing model.save in backbone js
从前端开始,使用backbone js我在做:
this.model.save()
.success(function (data) {
console.log("The response is " + JSON.stringify(data));
})
.error(function (error) {
console.log("The response is " + JSON.stringify(error));
})
从服务器端,模拟响应是
res.status(400).send({message: "Bad request"})
因此,我能够为 2XX 和非 2XX 状态打印在 res.send 方法中发送的对象。
但是,我还想 打印确切的状态 (从服务器发送到 res.status 的状态)。有人可以对此有所了解吗?
Backbone Ajax请求使用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,你会看到有3个参数。
您要找的是:
.success(function (data, statusText, xhr) {
console.log("The response status code is " + xhr.status);
})
从前端开始,使用backbone js我在做:
this.model.save()
.success(function (data) {
console.log("The response is " + JSON.stringify(data));
})
.error(function (error) {
console.log("The response is " + JSON.stringify(error));
})
从服务器端,模拟响应是
res.status(400).send({message: "Bad request"})
因此,我能够为 2XX 和非 2XX 状态打印在 res.send 方法中发送的对象。 但是,我还想 打印确切的状态 (从服务器发送到 res.status 的状态)。有人可以对此有所了解吗?
Backbone Ajax请求使用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,你会看到有3个参数。
您要找的是:
.success(function (data, statusText, xhr) {
console.log("The response status code is " + xhr.status);
})