Backbone - Getting raw response from server

2019-09-07 05:00发布

How do I get the raw response returned by the server when using POST/DELETE methods in Backbone (so you can't get the raw response in fetch/parse like GET)?

2条回答
神经病院院长
2楼-- · 2019-09-07 05:32

You can access the responseText from the server when the ajax call is complete.

The save, fetch, etc methods from Backbone provide the jQuery promise generated by the call to $.ajax.

When this promise has been resolved (e.g. the transaction is complete), you'll have access to the responseText property on the promise.

var promise = a_model.save();
$.when(promise).then(function(){
    console.log(promise.responseText); // if you're getting XML back it's `responseXML`
});

Here's the jQuery docs on the jqXHR object which is the promise object you get.

Additionally $.when and .then are described in the Deferred object documentation

查看更多
小情绪 Triste *
3楼-- · 2019-09-07 05:44

Why don't you just use the network tab in Chrome developer tools? That's the easiest way of viewing your raw requests and responses. Plus it is laid out in an easy to view format, showing cookies, timing values etc...

查看更多
登录 后发表回答