How to debug an Ajax request

I have a Rails application that generates HTML as follows:

<a href="/ReadItLater/stock?qid=5618572&amp" data-remote="true">stock it</a> 

When I click on this link in the browser, I can get information about the AJAX request on Firebug on the Console tab. I see a response to the request:

 $("#stock_5618528").hide(); 

enter image description here

But how can I set a breakpoint on this line and debug this code?

+4
source share
3 answers

If you change your answer to include the debugger keyword, it should hit it as a breakpoint. So in this case, the answer will look like this:

 debugger; $("#stock_5618528").hide(); 

Obviously remember to delete this when it goes live .: D

+11
source

Also, since you are using firebug.

Try using `console.log () '. It is very comfortable.

You can view the output after executing the script, rather than interrupting execution, and then deal with ajax timeouts.

All you may need is ...

 $.ajax({ url: "...", success: function(response){ console.log(response); } }); 
+5
source

InfernalBadger responded to a solution for front-end / script debugging. If you are interested in server-side debugging (i.e. in Rails code), do the following

  • Launch webrick with:
 rails server --debugger 
  • And add a debugger to the rails code / view, where you want to intercept it, to which you will get a console with all the loaded environment and context!
 <% debugger %> 
+3
source

Source: https://habr.com/ru/post/1347510/


All Articles