I am working on a custom piece where I am dynamically building very specific tables and writing them out using javascript after an AJAX call. I am trying to avoid writing custom code for each of these tables by coming up with a standard layout where I customize the layout via values in a JSON object stored in my current javascript file. Is there anyway I can store this object in another file and read it as if it were a properties file to make things neater?
views:
33answers:
3You need to dynamically load your additional javascript files. Here is a good article that portrays how to do that using static / dhtml methods.
Like m_oLogin said, you can dynamically load the additional scripts. Instead of doing as the article suggested, you can also use jquery to load the scripts -
$.getScript('script/loaded-script.js'), function() {
//action to execute after script is loaded
});
Javascript stored in separate files can be referenced as long as it is not wrapped somehow in a function, if so then you would need to reference that function. Thus JSON objects stored in separate files can be referenced - they are just Javascript (everything is an object in Javascript).
SO if you have simple object, or complex JSON:
myobject = "fred";
myobject2 = "wilma";
They can still be referenced, if they are in the same file, or not.
alert(myobject + myobject2);
shows "fredwilma"
Of course JSON objects would be more complicated, but the principle still applies.