views:

108

answers:

4

Project I'm working on uses jQuery.

I have a series of Ajax calls being made that load() other HTML fragments which in turn load() other fragments. The whole thing is confusing. I didn't write the code.

Is there any tool which will allow me to walk the callstack so I can figure what is calling a method? any browser tools that would help me figure this out?

Resolution:
In the end this was being caused because a <script src="..." was being injected in the server-side code. Your suggestions really helped - it was a combination of those and temporarily setting Ajax to sync instead async that helped me track down the issue.

$.ajaxSetup({
    async: false
});
+5  A: 

Firebug is capable of this.

When the debugger is paused, Firebug shows you the call stack, which is the set of nested function calls that are currently running and waiting to return.

The call stack is represented as a compact strip of buttons in the toolbar, each with the name of a function on the stack. You can click any button to jump to the line where that function is paused, and look at the local variables inside that function.

Robert Harvey
You can also use "console.trace()" from the console itself to see the detailed call stack once the debugger is paused.
Rajat
How do I pause at the exact right moment? Is there a console.pause?
tyndall
or should I just throw an alert inside the function in question?
tyndall
ok the alert idea isn't going to work.
tyndall
With Firebug, you can add a breakpoint to the line in question. Open the Script tab and double click on the line number.
S Pangborn
My problem is this app loads a default.aspx page and then everything else is a fake modal (via jQuery) so the Script tab doesn't show me anything useful.
tyndall
You can also call `console.trace()` directly from your code, so you don't even need to use the debugger.
Matthew Crumley
+5  A: 

Chrome also has a pretty wicked debugger built-in under Developer Tools, no add-ons/extensions needed.

pygorex1
+1  A: 

+1 for firebug. you can pause the debugger to walk the call stack http://getfirebug.com/javascript

kinet
+1  A: 

You might also want to try Opera's Dragonfly (available in any recent Opera build). I find it less refined than Firebug, but some errors are much more explicit under it.

jeanreis