Take the 2-minute tour ×

I have a page that sends an XHR request when a form is submitted and I would like to get Chrome to break when it receives a response. It seems like the best way to accomplish this would be if Chrome has a javascript function that I can call that breaks execution but I've been unable to find anything like that so far. Is there another solution?


I don't actually have a callback defined for the request so I can't set a breakpoint that way. The request is being sent with this line of jquery code:

$.post(this.action, $(this).serialize(), null, "script");

where this is a form element. The null argument is where you would usually define a callback but with the "script" argument, raw javascript is returned by the server and then directly executed, so it seems the only way to break and step through the code is with the debugger; statement. This works, but when stepping through the code you can't actually see which line you are on so its a little awkward. I suspect that this is a limitation of Chrome's debugging tools.

share|improve this question
I don't get it. If you null the callback, wouldn't all response be ignored? Where did you want the debugger to break at? –  syockit Aug 24 '10 at 9:41

3 Answers 3

You can just set a breakpoint in the success callback and step through the debugger. To set a breakpoint:

  1. Open "Developer Tools", and click the "Scripts" tab on the top.
  2. Select the script that contains the success callback for your AJAX request.
  3. Click the line number on the left hand side where you want the breakpoint. A blue arrow will show up indicating the breakpoint has been set.
  4. Then make the AJAX request as you would, and the debugger will automatically stop at the breakpoint you set.

Alternatively, you can use the debugger statement to automatically invoke the debugger. So with this your success callback may look like:

success: function(data, textStatus, request) {
    debugger; // pause execution and opens debugger at this point

Also checkout this nice article for debugging JavaScript.

However, the first approach is better as it doesn't require you to modify your code.

share|improve this answer
Thank you for the well thought out answer. The debugger statement definitely got me a lot closer. I edited my question to clarify that I don't actually have a callback function defined so setting a breakpoint with debugger seems to be the only option. –  delivarator Jul 15 '10 at 18:30
Thank you, Anurag! –  Kedar Mhaswade Dec 14 '12 at 17:48

You can also go to scripts tab in developer tool, and on the right side you click on XHR Breakpoints and add new breakpoint with url filtering.

If you use jQuery, when breakpoint occurs you can use CallStack to find your function that called jQuery.ajax.

share|improve this answer

drop down the chrome console (ctrl+shift+j) and type any of these:

Just rewrite the jquery ajax:

var prevajax = jQuery.ajax;
jQuery.ajax = function () { debugger; return prevajax.apply(jQuery, arguments); };

or if you are not using jQuery, rewrite the xhr class:

var prevxhr = XMLHttpRequest;
XMLHttpRequest = function (){debugger; prevxhr.apply(this, arguments);};

After it breaks, just press shift+f11 until you find the method which initiates the ajax request.

share|improve this answer
Thank you! This really helps when you're dealing with minified scripts over which you have no control. –  f.ardelian Oct 5 at 12:11

Your Answer


