How can I find out which Javascript is calling an Ajax request?

I had a problem with a Java JSF application: in a specific case, a user action triggers an Ajax HTTP request that updates the user interface correctly, but then a second request is immediately launched, causing a second incorrect update.

How can I find out (preferably using Firebug) exactly where the second request is launched? There's a lot of abbreviated JS code, so I don't know where to place breakpoints. Installing the onsubmit form onsubmit on console.trace did not help, I suppose, because these are independent Ajax requests.

+7
source share
5 answers

When testing sentences in the answers, I found that Firebug already has what I need out of the box: on the Console tab, all requests are displayed, and for Ajax requests it shows the file number and the line in which they occur, which tells me where to set the point stop ...

+5
source

Using Firebug, you can set Breakpoints in DOM mutation events (HTML) if you have some HTML changes in your UI update.

0
source

If a structure abstracts AJAX requests, you should be able to track calls for abstractions. For example, jQuery allows this through global AJAX event handlers .

Another, more reliable way to solve this problem is to replace the XHR object and the trace calls made for it (i.e. if the structure does not provide the above abstraction or if the calls you want to use do not use the abstraction). Just replace GM_log with console.trace in the script at the end of the page and include it in the page you GM_log testing.

0
source

What I personally did in this case is to use an HTTP proxy server, which can deliver a request or response β€œon hold”. For example. Burp Proxy (this is a security tool, but it is great for debugging purposes)

Launch the proxy server and configure the browser to use it. Go to the page where roque requests occur and activate intercept requests (this can take some time, because Burp Proxy can be quite a complex tool).

Now perform the user action, if everything goes well, the proxy intercepts it and waits for confirmation to pass. Do it. Then you will probably see the second request, which will also be intercepted by the proxy server. Don't let this go, but instead switch to Firebug and pause the debugger. Hope you can see where it comes from. Edit: secondly, the asynchronous nature of AJAX probably means that you cannot see what the exact location is with this method anyway ... :(

At the very least, you can also configure it to intercept responses. Both requests and responses can be edited on the fly, which is great for experimenting and debugging and can help narrow down the problem.

0
source

Perhaps this will help, the caller is the method in the Function javascript object.

console.log (arguments.callee.caller.toString ());

0
source

All Articles