如何找出哪个Javascript导致jQuery Ajax请求? [英] How to find out which Javascript causes a jQuery Ajax request?

查看:82
本文介绍了如何找出哪个Javascript导致jQuery Ajax请求?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从Ajax请求触发的地方找到Javascript代码?在Firebug的控制台中,我们能够识别文件和行号,但是如果我们使用 $ .ajax $。发布或jQuery的一些类似功能,它只会在Firebug的控制台中记录jQuery库文件。有没有办法获得jQuery函数的实际触发点?

How to find the Javascript code from where a Ajax request triggered? In Firebug's console we are able to identify the file and line number, but if we're using $.ajax or $.post or some similar function of jQuery, it will only log the jQuery library file in Firebug's console. Is there any way to get the actual trigger point of the jQuery function?

推荐答案

使用 Chrome DevTool 中的code>您有来源

Use Chrome in the DevTool you have Sources.

如果您打开这将在右侧看到 XHR / fetch Breakpoints ,如果你检查任何XHR 你的脚本会在每个停顿请求使用 XMLHttpRequest (因此请求不使用 jsonp 请求)。

If you open this you will see on the right side XHR/fetch Breakpoints, if you check Any XHR your script will pause at every request that uses XMLHttpRequest (so ever request that does not use jsonp for requests).

如果任何XHR 选项不可用(仅列出无断点),则你必须点击 + 当URL包含:字段时,请将中断留空并按Enter键。这将创建任意XHR 选项。 (感谢 Yasmin French 获取此信息)

If the Any XHR options are not available (only No Breakpoints is listed) then you have to click on the + leave the Break when URL contains: field blank and hit enter. This will create the Any XHR option. (Thanks to Yasmin French for this info)

使用调用堆栈(也在右侧),您将看到请求的来源是什么。

With the Call Stack (also on the right side) you will see what the origin of the request was.

但正如我所提到的那样,如果你想追踪这些请求,你就不会破坏 jsonp 请求你需要使用 jQuery的非缩小版本(或包括缩小版本的源图)并在其源中的正确部分设置断点。要查找此部分,您可以使用以下步骤:

But as I mentioned this does not break on jsonp requests if you want to trace these you need to use the not minified version of jQuery (or include the sourcemap of the minified version) and set a breakpoint in its source at the correct part. To find this part you can use the following steps:


  1. 创建 jsonp 请求在你的代码中并在这个地方设置断点。

  2. 调用代码的这一部分,以便切换到调试器。

  3. 使用进入,现在你应该在jQuery代码中。如果您现在在那里放置断点,Chrome将针对每个 jsonp 请求停止。

  1. Create a jsonp request in your code and set a breakpoint at this place.
  2. Call this part of your code so that you switch to the debugger.
  3. Use the Step into, now you should be in the jQuery code. If you now place a breakpoint there, Chrome will stop for every jsonp request.

注意:有时 Chrome (可能仅在 beta dev 版本中)在重新加载时往往会丢失断点,因此您需要检查它们在重新加载时是否仍然存在。

A note: Sometimes Chrome (probably only in the beta or dev versions) tends to lose the breakpoints on reloading, so you need to check if they still exist on reload.

这篇关于如何找出哪个Javascript导致jQuery Ajax请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆