要跟踪HTML文档上的所有AJAX调用,您可以覆盖
XMLHttpRequest原型。这样,您可以监视
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'; console.warn( 'Preparing ' + syncMode + ' HTTP request : ' + method + ' ' + url ); return open.apply(this, arguments);}function sendReplacement(data) { console.warn('Sending HTTP request data: ', data); if(this.onreadystatechange) { this._onreadystatechange = this.onreadystatechange; } this.onreadystatechange = onReadyStateChangeReplacement; return send.apply(this, arguments);}function onReadyStateChangeReplacement() { console.warn('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;使用此示例,对于每个AJAX调用,您都会在Javascript控制台中收到警告。
它不是jQuery脚本,但是您可以根据需要在内部使用jQuery。
此解决方案可能无法在IE 6或更早版本上运行,但可以在FF,IE7 +,Chrome,Opera,Safari …



