json - Global js var unreadable in jQuery + $.ajax -


morning all,

im trying populate global var called statusjson before .ready(), reason can access , read variable chrome console debug, script cant read var.

the code: http://jsfiddle.net/wiitohzjeh/pekyt/

as can see, json info obtained via $.ajax remote php file, create var simulating ajax-json response, , commented original $.ajax code.

the problem: reason chrome debug console return uncaught typeerror: cannot read property '0' of undefined

thanks :)

you need parse json object

replace below:

statusjson = ajaxdata; 

with

statusjson = $.parsejson(ajaxdata); 

and move $(function(){ status.init(); }); after status definition

updated fiddle


Comments