jeet_sen said:
I am loading the data with the following function:
The function is fine, your data file has syntax errors.
function loadScript (url, id, callback) {
var scriptElement = document.createElement('script');
scriptElement.type = 'text/javascript';
scriptElement.src = url;
scriptElement.id = id;
if (typeof scriptElement.addEventListener != 'undefined') {
scriptElement.addEventListener(
'load',
function (evt) { callback(); },
false
);
}
else if (typeof scriptElement.attachEvent != 'undefined') {
scriptElement.attachEvent(
'onreadystatechange',
function () {
if (scriptElement.readyState == 'complete') {
callback();
}
}
);
}
document.getElementsByTagName('head')[0].appendChild(scriptElement);
}
Function call:
// Load data
file2Load = 'test.js';
loadScript(file2Load,name,function () { alert(file2Load+"
loaded!!");} );
There is a syntax error here from auto-wrapping. When posting code,
manually wrap at about 70 characters so it can be quoted a couple of
times without wrapping.
var file2Load = 'test.js';
loadScript(file2Load,name,function () {
alert(file2Load + " loaded!!");
// Test availability of TABLE_ITEMS
alert(TABLE_ITEMS.name);
} );
But that's not the really problem...
test.js looks like this:
var TABLE_ITEMS = {
'name' : 'GS60H',
'level' : 'Library',
'child' : {
'gs60hcustom' : {
'qualis'
: {'status' : 'PASSED' },
'startAttributeCheck'
: {'status' : 'WAIVED' },
'availabilityCheck'
: {'status' : 'PASSED' },
'libAttributesCheck'
: {'status' : 'PASSED' },
--------------------------^^^
the extra comma here causes problems.
'checkViewConsistency' : {'status' : 'PASSED' },
'simModelsCompile'
: {'status' : 'FAILED' },
},
---------------------------------------------------^^^
As does this one. Formatting for posting would have helped. Firefox
was happy with it (surprisingly), only IE barfed for me.
},
'total' : 500,
'failed' : 20,
'waive' : 5
};
It's probably better to use machine-generation of such code, it's very
fussy doing it manually. Try building a form that generates the code in
a text area for copy/paste (for your local use only of course).
Try this version:
var TABLE_ITEMS = {
'name' : 'GS60H',
'level' : 'Library',
'child' : {
'gs60hcustom' : {
'qualis' : {'status' : 'PASSED' },
'startAttributeCheck' : {'status' : 'WAIVED' },
'availabilityCheck' : {'status' : 'PASSED' },
'libAttributesCheck' : {'status' : 'PASSED' },
'checkViewConsistency': {'status' : 'PASSED' },
'simModelsCompile' : {'status' : 'FAILED' }
}
},
'total' : 500,
'failed' : 20,
'waive' : 5
};