简体   繁体   中英

Debugging javascript code that comes as part of Ajax Response

So in my website, I use jquery to fetch data through ajax. AS part of the ajax response, some of the javascript code comes as well which is executed. The problem is how to debug this javascript in firebug or other tools. This is my experience so far:

  • putting debugger; doesn't work
  • For some javascript, can't set the breakpoint as that script is not yet loaded.
  • even if this new javascript calls some other function thats already loaded (ie i can see it in firebug and set a breakpoint), that breakpoint on that function is still not triggered

However, the javascript does executes normally and even things like console.log works but cant seem to debug it..

If you use Google Chrome, check out the answer of this question: https://stackoverflow.com/a/10929430/482916

You need to add in the ajax-loaded JS scripts the following comment:

//@ sourceURL=dynamicScript.js

where dynamicScript.js is the name of the script which will come up in the console.

I know Firebug and the IE developer tools will respect the debugger statement. So I would throw that onto the top of the response.

debugger;

func1();
func2();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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