I'am loading html with some inline javascript on a $.post callback. Something "like that" :-)
我在$ $上加载一些内联javascript的html。回调。“这样”的东西:-)
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.
但是当我这样做的时候,我看不到新的内联javascript加载在Chrome的Scripts项上。我看到Network选项卡上的JS正在执行,但是我不能调试这段代码。
Any idea about how to debug this code? Thanks!
关于如何调试这段代码有什么想法吗?谢谢!
1 个解决方案
#1
8
All modern JS engines do allow to generate a javascript break-point "in-code".
所有现代JS引擎都允许生成一个javascript断点“in-code”。
To do that, you need to execute the debugger;
statement somewhere in your code. As soon as the js engine reads that command, a break point is set and the debugger is loaded.
为此,需要执行调试器;语句在代码中的某处。一旦js引擎读取该命令,就会设置断点并加载调试器。
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);
#1
8
All modern JS engines do allow to generate a javascript break-point "in-code".
所有现代JS引擎都允许生成一个javascript断点“in-code”。
To do that, you need to execute the debugger;
statement somewhere in your code. As soon as the js engine reads that command, a break point is set and the debugger is loaded.
为此,需要执行调试器;语句在代码中的某处。一旦js引擎读取该命令,就会设置断点并加载调试器。
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);