Reputation: 24873
I use jQuery to make an ajax request and add the code to my page. The code that I add to the page not only contains HTML, but also javascript.
Apparently the javascript-code is not being called! How can I force to my newly added javascript sourcecode being executed?
Upvotes: 0
Views: 383
Reputation: 6299
You probably are using the jQuery(element).load(url) method.
jQuery uses the browser's .innerHTML property to parse the retrieved document and insert it into the current document. During this process, browsers often filter elements from the document such as , , or elements. As a result, the elements retrieved by .load() may not be exactly the same as if the document were retrieved directly by the browser.
Try to scope the content that you are receiving from the server, for example:
// will load only the content inside the element with id="container"
jQuery(element).load("yoururl #container");
You probably should try to execute the JS code from the script, using the complete callback, for example:
jQuery(element).load("yoururl #container", function(response, status, xhr) {
do_stuff_after_load();
}
Upvotes: 1