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

Why can't I seedebug javascript loaded with jquery.html() with Chrome - Stack Overflow

programmeradmin2浏览0评论

I'am loading html with some inline javascript on a $.post callback. Something "like that" :-)

callback{
response_data = '<p>string with html and </p><script "javascript">var scripts...</script>'
jQuery('#selector').html(response_data);
}

But when I do that, I can't see the new inline javascript loaded on Chrome's Scripts Tab. I see that JS on Network tab and js is executing but I can't debug this code.

Any idea about how to debug this code? Thanks!

I'am loading html with some inline javascript on a $.post callback. Something "like that" :-)

callback{
response_data = '<p>string with html and </p><script "javascript">var scripts...</script>'
jQuery('#selector').html(response_data);
}

But when I do that, I can't see the new inline javascript loaded on Chrome's Scripts Tab. I see that JS on Network tab and js is executing but I can't debug this code.

Any idea about how to debug this code? Thanks!

Share Improve this question asked Dec 13, 2011 at 12:48 rubdottorubdotto 8,31811 gold badges41 silver badges60 bronze badges 2
  • have a look at Console tab, right click and select check XMLHTTPRequest – cristian Commented Dec 13, 2011 at 12:50
  • Because i suppose browsers do not listen to asynchronous calls to update the list of avaiable files – Pawan Commented Dec 13, 2011 at 12:51
Add a ment  | 

1 Answer 1

Reset to default 8

All modern JS engines do allow to generate a javascript break-point "in-code".

To do that, you need to execute the debugger; statement somewhere in your code. As soon as the js engine reads that mand, a break point is set and the debugger is loaded.

You might want to give that a shot. It might still not work correctly since dynamic script insertion can still be trouble and pain, depending how and when you do it.

It would definately a better idea to do it more "accurate" by creating and inserting a new script element

var myscript = document.createElement('script');
myscript.textContent = 'var scripts = 42; alert("hello");';
myscript.type = 'text/javascript';

document.body.appendChild(myscript);
发布评论

评论列表(0)

  1. 暂无评论