Set a JSON object in a Javascript function and pass it to another function -
i'm trying set json object javascript function , use parameter in function, obj has no value outside function. created json object outside function:
var obj = {"level":0, "index":0, "count":0, "aabb":[], "point":[], "children":[]}; then
function loadxmldoc() { if(window.xmlhttprequest){ xmlhttp=new xmlhttprequest(); } else { xmlhttp=new activexobject("microsoft.xmlhttp"); } xmlhttp.onreadystatechange=function(){ if(xmlhttp.readystate==4 && xmlhttp.status==200){ var string = xmlhttp.responsetext; obj = json.parse(string); document.getelementbyid("mydiv").innerhtml = obj.children; } } xmlhttp.open("get","r0.json",true); xmlhttp.send(); return obj; } but after call function , pass obj, this:
var obj = loadxmldoc(); initgl(canvas); initshaders(); initbuffers(obj); it cannot pass value function initbuffers. why did happen , how can solve that? thanks.
i not sure mean when cannot pass obj parameter, 1 thing realize onreadystatechange handler called asynchronously, after call initbuffers. perhaps, need call initialization routines inside handler, when json response parsed.
Comments
Post a Comment