How to get headers from response?

I need to get headers when readyState это 4.

I have had this code:

    <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 ответ

Ты можешь использовать getResponseHeader(),

Другие вопросы по тегам