views:

13

answers:

1

So Firefox+Firebug seems to be the tool of choice for debugging jQuery. Its certainly very handy.

I can get breakpoints in JavaScript code that was there when the page originally loaded (the breakpoint-able lines show up with green line numbers in Firebug).

But when jQuery code gets returned by an Ajax call, I can't get breakpoints to attach to it. Is this even possible?

For example when the result of an Ajax call is a load of html that I plug into a DIV, and that html also includes some jQuery code to attach a new click handler to a button ... How do I get a breakpoint in the click handler?

(NB: It took me a while to find where the JavaScript that gets returned from Ajax calls shows up - in the toolbar of the FireBug Script tab, you have to click on the second dropdown to show a list of JavaScript snippets)

+1  A: 

I think this is not possible, cause ajax code is not inserted from a file.

What you can do though is to manualy insert a debugger; statement into the js code when receiving the ajax result.

Thariama
You mean get the server to add `debugger;` statements? Thanks.
codeulike
you can do that or you insert them onSuccess in after the request has been received
Thariama
Ah right, I see. Is the general principle with FireBug that javascript thats in a file can be debugged? If so, I could move most of my jQuery functions into a pre-prepared file and only add the event handlers dynamically. Would that then let me place breakpoints in the pre-prepared stuff?
codeulike
hmm, i am not that sure - but you should give it a try :)
Thariama