骨干提取完成后获取响应标头

asi*_*haq 4 javascript ajax backbone.js

我需要在backbone.js fetch方法的Ajax请求中读取响应头.如果我覆盖了fetch方法,有没有办法读取标题:

var PageCollection = Backbone.Collection.extend({

    url: 'http://localhost/cms?_mn=Mod_Admin&_mf=getAllPages',

    model: PageModel,

    fetch: function (options) {
        Backbone.Collection.prototype.fetch.call(this, options);
        // The above line of code works and fetch the dataset 
        // BUT how i can read the response headers at this point
    }
});
Run Code Online (Sandbox Code Playgroud)

Naz*_*zar 16

使用"success"回调来获取xhr对象,这样您就可以获得所有响应头:

collection.fetch({
    success: function (collection, response, options) {
        options.xhr.getAllResponseHeaders(); // To get all the headers
        options.xhr.getResponseHeader('header_name'); // To get just one needed header
    }
});
Run Code Online (Sandbox Code Playgroud)