How to find out which Javascript causes a jQuery Ajax request?

Use Chrome in the DevTool you have Sources.

If you open this you will see on the right side XHR/fetch Breakpoints, if you check Any XHR your script will pause at every request that uses XMLHttpRequest (so ever request that does not use jsonp for requests).

If the Any XHR options are not available (only No Breakpoints is listed) then you have to click on the + leave the Break when URL contains: field blank and hit enter. This will create the Any XHR option. (Thanks to Yasmin French for this info)

With the Call Stack (also on the right side) you will see what the origin of the request was.

But as I mentioned this does not break on jsonp requests if you want to trace these you need to use the not minified version of jQuery (or include the sourcemap of the minified version) and set a breakpoint in its source at the correct part. To find this part you can use the following steps:

  1. Create a jsonp request in your code and set a breakpoint at this place.
  2. Call this part of your code so that you switch to the debugger.
  3. Use the Step into, now you should be in the jQuery code. If you now place a breakpoint there, Chrome will stop for every jsonp request.

A note: Sometimes Chrome (probably only in the beta or dev versions) tends to lose the breakpoints on reloading, so you need to check if they still exist on reload.

Leave a Comment