XMLHttpRequest 事件更改

var open = window.XMLHttpRequest.prototype.open,
            send = window.XMLHttpRequest.prototype.send,
            onReadyStateChange;

        function openReplacement(method, url, async, user, password) {
            var syncMode = async !== false ? 'async' : 'sync';
            alert('Preparing ' +syncMode +' HTTP request : ' + method + ' ' + url
    );
            return open.apply(this, arguments);
        }

        function sendReplacement(data) {
            alert('Sending HTTP request data : ', data);

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

            return send.apply(this, arguments);
        }

        function onReadyStateChangeReplacement() {
            alert('HTTP request ready state changed : ' + this.readyState);
            if (this._onreadystatechange) {
                return this._onreadystatechange.apply(this, arguments);
            }
        }

        window.XMLHttpRequest.prototype.open = openReplacement;
        window.XMLHttpRequest.prototype.send = sendReplacement;

posted on 2011-10-14 15:37  Henry_Wang  阅读(1346)  评论(0编辑  收藏  举报

导航