如何从响应中获取标题?

时间:2013-06-01 12:21:02

标签: javascript xmlhttprequest xmlhttprequest-states

我需要在readyState为4时获取标题。

我有这段代码:

    <script type='text/javascript'>
        var open = window.XMLHttpRequest.prototype.open,
            send = window.XMLHttpRequest.prototype.send,
            onReadyStateChange;

        var sendReplacement = function(data) {
            console.log('Sending HTTP request data : ', data);

            if (this.onreadystatechange) {
                this._onreadystatechange = this.onreadystatechange;
            }
            this.onreadystatechange = onReadyStateChangeReplacement;

            return send.apply(this, arguments);
        };

        var onReadyStateChangeReplacement = function() {
// GET HEADERS
            console.log('HTTP request ready state changed : ' + this.readyState);
            if (this._onreadystatechange) {
                return this._onreadystatechange.apply(this, arguments);
            }
        };

        window.XMLHttpRequest.prototype.send = sendReplacement;

    </script>

有可能吗?

1 个答案:

答案 0 :(得分:0)

您可以使用getResponseHeader()