tags:

views:

47

answers:

3

This question might be a bit stupid, but how can I access the data returned from the xhrGet outside of the get itself? Firebug shows that the "json" object has an array called results, which stores the json Object from the response, but when I try to access it it is null. So: how do I access the received data on the last code line? Thanks, Martin

var json = dojo.xhrGet({ url :'/disease_web/graphMlDownload/getEdgeInformation/', handleAs:"json",content : { edgeid : edgeId, graphname:this._canvas.path},

  load:function(response){

    return response;
   }

}); console.log(json.ioArgs); console.log(json.results);

A: 

By default dojo.xhrGet is called asynchronously, so console.log(json.results) is null because it's run just after dojo.xhrGet, but before response comes from server.

var xhrGet = dojo.xhrGet({
        url: "/some_rul",
        handleAs: "json",
        handle: function(response) {
            console.info(2,'response',response);                
            console.info(3,'xhrGet.results[0]',xhrGet.results[0]);
        }
 });
 console.info(1,xhrGet.hasOwnProperty('results')); 

The result is:

1 false

2 response - ['some data from server']

3 xhrGet.results[0] - same data as in 'response' accessed via xhrGet

keemor
A: 

how can I access the response outside of this function? I want to use the data in another function, but calling this function from within doesn't execute it somehow. I'm a total noob in this field, so please forgive my stupidness...

Martin Lechner