6

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!

2
  • have a look at Console tab, right click and select check XMLHTTPRequest Commented Dec 13, 2011 at 12:50
  • Because i suppose browsers do not listen to asynchronous calls to update the list of avaiable files Commented Dec 13, 2011 at 12:51

1 Answer 1

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 command, 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);
Sign up to request clarification or add additional context in comments.

1 Comment

The debugger; is a good chance. Anyway I move all JS to .js files to solve it :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.