简体   繁体   English

JavaScript中的请求来自何处?

[英]Where in JavaScript is the request coming from?

I am debugging a large, complex web page that has a lot of JavaScript, JQuery, Ajax and so on. 我正在调试一个包含大量JavaScript,JQuery,Ajax等的大型复杂网页。 Somewhere in that code I am getting a rouge request (I think it is an empty img) that calls the root of the server. 在该代码的某处,我收到一个调用服务器根目录的请求(我认为它是一个空的img)。 I know it is not in the html or the css and am pretty convinced that somewhere in the JavaScript code the reqest is being made, but I can't track it down. 我知道它不在html或css中,并且我非常确信在JavaScript代码中的某个地方正在制作请求,但我无法追踪它。 I am used to using firebug, VS and other debugging tools but am looking for some way to find out where this is executed - so that I can find the offending line amongst about 150 .js files. 我习惯使用firebug,VS和其他调试工具,但我正在寻找一些方法来找出它的执行位置 - 这样我就可以找到大约150个.js文件中的违规行。

Apart from putting in a gazzillion console outputs of 'you are now here', does anyone have suggestions for a debugging tool that could highlight where in Javascript requests to external resources are made? 除了输入“你现在在这里”的gazzillion控制台输出之外,是否有人建议调试工具可以突出显示Javascript对外部资源的请求的位置? Any other ideas? 还有其他想法吗?

Step by step debugging will take ages - I have to be careful what I step into (jQuery source - yuk!) and I may miss the crucial moment 一步一步的调试将需要很长时间 - 我必须小心我踏入(jQuery源 - yuk!)我可能会错过关键时刻

What about using the step-by-step script debugger in Firebug ? 如何在Firebug中使用逐步脚本调试器?

I also think that could be a very interesting enhancement to Firebug, being able to add a breakpoint on AJAX calls. 我也认为这可能是Firebug的一个非常有趣的增强,能够在AJAX调用上添加断点。

You spoke of jQuery source... 你谈到了jQuery源代码......

Assuming the request goes through jQuery, put a debug statement in the jQuery source get() function, that kicks in if the URL is '/'. 假设请求通过jQuery,将调试语句放在jQuery源get()函数中,如果URL为'/'则启动。 Maybe then you can tell from the call stack. 也许那时你可以从调用堆栈中判断出来。

You can see all HTTP request done through JavaScript using the Firebug console. 您可以使用Firebug控制台查看通过JavaScript完成的所有HTTP请求。

If you want to track all HTTP requests manually, you can use this code: 如果要手动跟踪所有HTTP请求,可以使用以下代码:

$(document).bind('beforeSend', function(event, request, ajaxOptions)
{
   // Will be called before every jQuery AJAX call
});

For more information, see jQuery documentation on AJAX events . 有关更多信息,请参阅有关AJAX事件的jQuery文档

If its a HTTPRequest sent to a web server, I would recommend using TamperData plugin on Firefox. 如果将HTTPRequest发送到Web服务器,我建议在Firefox上使用TamperData插件。 Just install the plugin, start tamper data, and every request sent will be prompted to tamper/continue/abort first. 只需安装插件,启动篡改数据,每个发送的请求都会被提示首先篡改/继续/中止。

Visit this page at Mozilla website 在Mozilla网站上访问此页面

Just a guess here, but are you using ThickBox? 这里只是一个猜测,但你在使用ThickBox吗? It tries to load an image right at the start of the code. 它尝试在代码的开头加载图像。

First thing I would do is check whether this rouge request is an Ajax request or image load request via the Net panel in Firebug. 我要做的第一件事是通过Firebug中的Net面板检查此rouge请求是Ajax请求还是图像加载请求。

If it's Ajax, then you can overload the $.ajax function with your own and do a strack trace and include the URL requested before handing off to the original $.ajax. 如果它是Ajax,那么您可以使用自己的方法重载$ .ajax函数并执行一个strack跟踪并在转移到原始的$ .ajax之前包含所请求的URL。

If it's an image, it's not ideal, but if you can respond to the image request with a server side sleep (ie php file that just sleeps for 20 seconds) you might be able to hang the app and get a starting guess as to where the problem might be. 如果它是一个图像,它不是理想的,但如果您可以通过服务器端睡眠响应图像请求(即只睡眠20秒的PHP文件),您可能可以挂起应用程序并获得关于哪里的开始猜测问题可能是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM