骨干-从服务器获取原始响应 [英] Backbone - Getting raw response from server
问题描述
在Backbone中使用POST/DELETE方法时,如何获取服务器返回的原始响应(因此您无法在 fetch
/ parse
中获取原始响应像GET)?
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)?
推荐答案
您可以在ajax调用完成后从服务器访问 responseText
.
You can access the responseText
from the server when the ajax call is complete.
Backbone的 save
, fetch
等方法提供了通过调用 $.ajax
生成的jQuery Promise.
The save
, fetch
, etc methods from Backbone provide the jQuery promise generated by the call to $.ajax
.
此承诺已解决(例如交易完成)后,您将可以访问该承诺的 responseText
属性.
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`
});
这是jqXHR对象上的 jQuery文档,这是您获得的promise对象
Here's the jQuery docs on the jqXHR object which is the promise object you get.
.then
.rel ="nofollow">延迟的对象文档
Additionally $.when
and .then
are described in the Deferred object documentation
这篇关于骨干-从服务器获取原始响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!