我知道如何在浏览器的dev工具中查看网络流量,并在控制台中显示XMLHttpRequests,但是是否有一个显示所有网络流量的窗口属性?
发布于 2014-09-11 17:43:41
用jquery。
如果您没有它,您只需扩展XMLHttpRequest.prototype.open来触发自定义事件。
发布于 2014-09-11 17:46:45
(function ($) {
// The ajaxSend() method is a callback which is fired
every time a jQuery AJAX call is completed.
$(document).ajaxSend(function(event, xhr, settings){
if (iswantedurl(settings.url.pathname)){
// ga('send','pageview',settings.url.pathname);
}
});
})(jQuery);原产地代码来自如何扩展以跟踪AJAX等(根据H5BP文档)
发布于 2014-09-11 18:22:30
纯JavaScript:
XMLHttpRequest.prototype.open = function(method, url, async, user, password) {
// Add my code to record all the requests
if (!window.XMLLog) window.XMLLog = [];
window.XMLLog.push(this);
// Don't break the original JS
return this.xhr.open(method, url, async, user, password);
}jQuery:
$(document).ajaxSend(function(event, xhr, settings){
if (!window.XMLLog) window.XMLLog = [];
window.XMLLog.push({event:event,xhr:xhr,settings:settings});
});https://stackoverflow.com/questions/25793764
复制相似问题