本主题可能对您有所帮助:拦截所有 ajax 调用?
实际上,您可以重新定义 XHR 以使 ajax 调用按照您的意图进行,而不依赖于 Javascript 框架:
var ajax_urls = new Array();
var XHR_backup = new Array();
XHR_backup.open = XMLHttpRequest.prototype.open;
XHR_backup.send = XMLHttpRequest.prototype.send;
// Customize XHR behaviour
(function(XHR, ajax_urls) {
"use strict";
var open = XHR.prototype.open;
var send = XHR.prototype.send;
XHR.prototype.open = function(method, url, async, user, pass) {
ajax_urls.push(url);
};
XHR.prototype.send = function(data) {
}
})(XMLHttpRequest, ajax_urls);
// Evaluate your script
eval(resultScript);
for (var i = 0; i < ajax_urls.length; i++) {
alert('Hey, my super XHR fetched ' + ajax_urls[i] + ' !!');
}
// Restore initial XHR behaviour
XMLHttpRequest.prototype.open = XHR_backup.open;
XMLHttpRequest.prototype.send = XHR_backup.send;
编辑:我还没有测试过这个片段,所以我正在等待你的反馈。
Edit2:测试和工作!http://jsfiddle.net/3qVUP/1/