admin管理员组文章数量:1355665
Is there any way to know (with some developers tools: chrome, Firefox, Opera, etc) what is last function that fires an AJAX call?
It would be interesting for debugging web apps.
Thank you
Is there any way to know (with some developers tools: chrome, Firefox, Opera, etc) what is last function that fires an AJAX call?
It would be interesting for debugging web apps.
Thank you
Share Improve this question edited Jun 12, 2013 at 14:54 rodrigo-silveira 13.1k13 gold badges79 silver badges134 bronze badges asked Jun 12, 2013 at 13:46 MrViSiOnMrViSiOn 1912 silver badges17 bronze badges 4- firebug or chrome developer tools are very powerful for debugging web apps, they basically have all features you could wish for – x4rf41 Commented Jun 12, 2013 at 13:49
- What does "throws an AJAX call" mean? Makes a call ? (only errors are thrown). By "last function" do you mean the function which most recently made an Ajax call at some point in time? – Felix Kling Commented Jun 12, 2013 at 13:50
- @x4rf41 The poster is asking how to do it, not can it do it. – epascarello Commented Jun 12, 2013 at 13:50
- I assume "throws" means "executes" – epascarello Commented Jun 12, 2013 at 13:55
5 Answers
Reset to default 7Here's how I do it in Google Chrome:
- Load your web app
- Press F12 to open Chrome Developer Tools
- Go to the Profiles tab
- Select Collect JavaScript CPU Profile
- Press Start
- Use your web app as you normally would
- When you're done using the web app, go back to Developer Tools and press Stop
As a result, you'll get a profile similar to the one shown in the picture below. This profile shows every JavaScript call made during the time you were capturing the profile, including any AJAX calls, as well as where in your code the call was made (which function "threw" the call).
As you can see in this other screenshot, I had an AJAX call fired from my script (dash.js, line 51), from a function called doOnSelectDate(), which was itself called from a function called getDailySummary() (defined on line 60).
Look at console.trace()
, it will give you the stack info you are after.
Here's how to do this in Firefox and Chrome. For both I used W3Schools jQuery example here so you can follow along exactly.
For Firefox.
Trigger the event that calls the AJAX. Open up Firebug console and click the source link.
If you wrote your own low level AJAX function this will be enough and will take you to your source. But since most people will be using jQuery minimized you get the jquery.min.js link which is no help.
If you are using jquery.min.js, click on the link in the console and set a breakpoint at the line specified in the link (line 6).
Now trigger the AJAX again and it will stop at the breakpoint. Click on the stack tab and your call should be somewhere in there. Click on it and it will take you to the source.
For Chrome
Open settings and enable "Log XMLHttpRequests"
Run your AJAX again and it will appear in the console. Expand it to see the stack trace.
you can use firebug in firefox. It allows you to have breakpoints in javascript code.
You can click on the script tab of firebug and select your script file and provide breakpoints at all AJAX calls and see which AJAX is being called last.
Google chrome has developer tools: view -> developer -> developer tools
you are probably most interested in the network tab.
Firebug is also really good for debugging and the console there will show you the ajax requests. Firebug is a firefox addon.
本文标签: AJAX Getting ajax call javascript functionStack Overflow
版权声明:本文标题:AJAX: Getting ajax call javascript function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743996958a2573165.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论