I'd like to load an external JavaScript file, using jQuery, asynchronously, and then be able to call functions loaded from the external JavaScript. I'm including my JS file at the bottom of my html, just before </html>
. The jQuery code is just before my code.
I'm trying this:
(function(){
$(document).ready(function() {
obj.init();
});
var obj = {
init:function(){
$.ajax({
url: 'http://domain.com/script.js',
dataType: 'script',
success: function() {
obj.dostuff();
}
});
},
dostuff:function() {
// ...do stuff
}
}
window.obj = obj;
})();
The Chrome JavaScript console is reporting this:
Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.
I'm trying to keep all my JS in one file, all in objects (classes & functions style), and then call each class (an init()
function) from within the $(document).ready();
.
What am I doing wrong here..?