如何捕获正在调用的 Javascript 函数?

发布于 2024-09-26 16:27:28 字数 240 浏览 5 评论 0原文

我正在使用 COGNOS,这是一个非常令人沮丧的 BI 应用程序,严重依赖 Javascript。基本上,当

有没有办法使用 Firebug 显示正在调用的不同函数?我的做法正确吗?

I'm working with COGNOS, a very frustrating BI application that relies heavily on Javascript. Basically, when a <select> box is changed, the data on screen is refreshed, presumably by an AJAX function or something similar. I'd like to force this change using jQuery, but I'm not sure how to intercept the call it is making so I can duplicate it. There's also a metric ton of JS code, so it's hard to find by hand.

Is there a way using Firebug to display the different functions being called? Is my approach correct?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

十秒萌定你 2024-10-03 16:27:28

如果您打开 Firebug 脚本 面板,左上角有一个看起来像电视遥控器上的暂停按钮的按钮:||。这告诉 Firebug 在下一段运行的 JavaScript 上暂停。因此,我将打开页面,确保启用脚本面板,单击该按钮,然后更改选择框。 应该在 Firebug 中触发一个断点,之后您可以单步执行代码以找出何时调用什么。

或者,如果您不介意使用其他工具,Google Chrome 有一个内置的调试器和检查器它可以向您显示附加到元素的事件处理程序。所以在Chrome中,如果你打开页面,右键点击选择框并选择检查元素,那么在底部的右侧应该有一个附加到它的事件处理程序的列表。这可能更容易使用。

最后,在任一工具中,如果您可以识别内部实际导致数据重新加载的代码位(例如,通过查找 URL,或 XmlHTTPRequest 实例,或 jQuery 的 .ajax.post.get.getJSON 函数(如果使用 jquery),您可以在其上放置断点然后触发选择,然后查看调用堆栈(在两个工具的右侧)。

祝你好运!

If you open the Firebug Script panel, on the top left there's a button that looks like a pause button on a TV remote: ||. That tells Firebug to pause on the next bit of JavaScript that runs. So I'd get the page open, ensure that the Script panel is enabled, click that button, then change the select box. That should trigger a breakpoint in Firebug, after which you can step through the code to figure out what's being called when.

Alternately, if you don't mind using a different tool, Google Chrome has a built-in debugger and inspector which can show you the event handlers attached to an element. So in Chrome, if you bring up the page, right-click the select box and choose Inspect Element, then on the right-hand side at the bottom there should be a list of the event handlers attached to it. That may be a bit easier to work with.

Finally, in either tool, if you can identify the bit of code in the guts that's actually causing the data reload (by looking for a URL, for instance, or an XmlHTTPRequest instance, or jQuery's .ajax, .post, .get, or .getJSON functions if it's using jquery), you can put a breakpoint on that and then trigger the select, then look at the call stack (on the right-hand side in both tools).

Good luck!

清风疏影 2024-10-03 16:27:28

遗憾的是,此时您可能最好在 Cognos 中使用老式的警报框调试方法。 IBM 表示,较新版本的 Cognos 将在 Firefox 中运行,但 IBM 之前的代码非常以 IE 为中心,甚至在新版本的 IE 中也不是特别好。您还可以在较新版本的 IE 中使用 F12 调试器功能,这有时很有用。我并不假装这一切都和 Firebug 一样好。

另外,关于您尝试调试的实际问题,如果您在编辑报告时单击 Cognos 中的选择,则有一个名为“自动提交”的参数。如果将其更改为“否”,则无需禁用 jQuery 中的行为。

Sadly, at this point, you are probably best off in Cognos using the old-fashioned alert box method of debugging. IBM has said that newer versions of Cognos will work in Firefox, but the pre-IBM code was very IE-centric, and not even especially good in new versions of IE. You can also use the F12 debugger functionality in newer versions of IE, which is sometimes useful. I don't pretend any of this is as good as Firebug.

Also, with regard to the actual problem you were attempting to debug, the select in Cognos, if you click on it while editing the report, has a parameter called "Auto-submit". If you change that to "no", then you won't need to disable the behavior in jQuery.

上课铃就是安魂曲 2024-10-03 16:27:28

如果您使用的是 Firefox + Firebug,您可以激活“net”选项卡并检查所有正在进行的 Ajax 调用。 (查看 XHR 按钮下方)

If you're using Firefox + Firebug you can activate the "net" tab and examine all of the Ajax calls being made. (look under XHR button)

酒中人 2024-10-03 16:27:28

在 Firefox 中选择该元素,查看其 onclick 事件是什么,或者它是否有 ID,然后在 JS 文件中搜索该 ID。

Select the Element in Firefox and see what its onclick event is or if it has an ID then search the JS file for that ID.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文