最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to debug Ajax request - Stack Overflow

programmeradmin4浏览0评论

I have a Rails application which generate HTML like this:

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

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

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

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

I have a Rails application which generate HTML like this:

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

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

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

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

Share Improve this question edited Apr 11, 2011 at 8:40 ceth asked Apr 11, 2011 at 8:29 cethceth 45.3k63 gold badges188 silver badges300 bronze badges 4
  • I am not getting this... can you please elaborate a bit looks like i am not understanding the question. As looks like you have firebug and after setting a break point you should be able to debug code. – Anil Namde Commented Apr 11, 2011 at 8:35
  • I have added the screenshot for my answer. I get javasript on Console tab (Answer) and I can't set the breakpoint here. – ceth Commented Apr 11, 2011 at 8:41
  • So $("#stock_5618528").hide(); is the output from the server in response to the AJAX request? – lonesomeday Commented Apr 11, 2011 at 8:42
  • Yes. But I need to debug execution of this output. – ceth Commented Apr 11, 2011 at 8:53
Add a comment  | 

3 Answers 3

Reset to default 11

If you change your response to include the debugger keyword it should hit that as a breakpoint. So in this case the response would be:

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

Obviously don't forget to remove that when it goes live. :D

Also, since you're using firebug.

Try using using `console.log()'. It is extremely handy.

You can view your output after your script has executed rather than interrupting execution and then having to deal with ajax timeouts.

All you might need to do is..

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

InfernalBadger responded with a solution for front-end/script debugging. If you're interested in debugging at the server side (ie in the Rails code), do the following

  1. Start webrick with:
rails server --debugger
  1. And add debugger in the rails code/view where you'd like it to breakpoint, reaching which you'll get a console with all the environment and context loaded up!
<% debugger %>
发布评论

评论列表(0)

  1. 暂无评论