Debugging javascript code that comes as part of Ajax Response

微笑、不失礼 提交于 2019-12-12 18:58:40

问题


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 (i.e. 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..


回答1:


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.




回答2:


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();


来源:https://stackoverflow.com/questions/4716957/debugging-javascript-code-that-comes-as-part-of-ajax-response

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!