Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX: Getting ajax call javascript function

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

like image 360
MrViSiOn Avatar asked Jun 12 '13 13:06

MrViSiOn


People also ask

How do I call AJAX method from another AJAX method?

You can set the option "async" to false (for the first ajax call). This means that function 2 will be called after function 1 has received a response, i.e. finished it's execution.

What is JavaScript AJAX call?

What's AJAX? AJAX stands for Asynchronous JavaScript And XML. In a nutshell, it is the use of the XMLHttpRequest object to communicate with servers. It can send and receive information in various formats, including JSON, XML, HTML, and text files.

How do I know if AJAX is working?

In Laravel, we can use $request->ajax() method to check request is ajax or not.


1 Answers

Here's how I do it in Google Chrome:

  1. Load your web app
  2. Press F12 to open Chrome Developer Tools
  3. Go to the Profiles tab
  4. Select Collect JavaScript CPU Profile
  5. Press Start
  6. Use your web app as you normally would
  7. 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).

enter image description here

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).

enter image description here

like image 66
rodrigo-silveira Avatar answered Sep 28 '22 05:09

rodrigo-silveira