I currently have a Javascript file in called config.js in a dirtectory called static. The contents of the file is currently:
var config = {"config1": "test1", "config2": 1};
I also have the following function and it's associated call at the end of the script:
function updateConfig() {
var fileRef = document.createElement('script');
fileRef.setAttribute("type", "text/javascript");
fileRef.setAttribute("src", "/static/config.js");
headElem = document.getElementsByTagName("head")[0];
headElem.appendChild(fileRef);
}
updateConfig();
test.innerText = config.config1;
However, when I run the script I get the following error in Firebug:
ReferenceError: config is not defined
How do I get my JS file to be loaded dynamically into my page? If I just put the link to config.js statically into the it works without a problem.