Javascript Does Not Work Upon Ajax Call
I have a page which does an AJAX call and loads an entire page. The page that gets loaded has some Javascript. The javascript works on page by itself when loaded, but when its gets
Solution 1:
Javascript loaded in HTML through AJAX will not be executed.
If you want to include scripts dynamically, append <script>
tags to the existing loaded page's <head>
element.
Solution 2:
execute the script with jquery rather than with innerHTML
//this is not working! document.getElementById("chart-content").innerHTML = this.responseText;
//try this
$("#chart-content").html(this.responseText);
Solution 3:
The script is outside the body tag, and the loader picks out only the code inside the body tag, so the script is not even part of what you add to the page.
Solution 4:
Loading you Js within the <head>
should work. use this.
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', loadJs);
} else {
loadJs();
}
functionloadJs() {
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = '/assets/script/editor-controlls.js';
script.defer = truedocument.getElementsByTagName('head')[0].appendChild(script);
}
Post a Comment for "Javascript Does Not Work Upon Ajax Call"