javascript - Load JSON file, error undefined -
i'm trying load json file i'll use constants file, i'm getting error undefined, 1 help?
here code:
function loadjsonfile(filepath){ $.getjson(filepath, function(mydata) { alert(mydata.length); return mydata; }) error(function() { alert("error"); }); the structure of constants file is:
{ "var1":"v1", "var2":"v2" } thank in advance help.
function loadjsonfile(filepath, callback){ $.getjson(filepath) .success(function(mydata) { callback(data); }) .fail(function() { alert("error")}); ; }); function dostuff(data){ alert(data.var1) } loadjsonfile('url', dostuff);
Comments
Post a Comment