Login Register

<Solved>dojo1.0 dojo.xhrGet

I am new to Dojo. I am trying to get JSON data from server. Here I have written code

var series=dojo.xhrGet({
           url: "actions/seriesBuilder.jsp",
           handleAs: "json",
           timeout: 5000,
           load: function(response, ioArgs) {
                    console.log(response);
                   
                   return response;
                 },
            error: function(response, ioArgs) {
                      console.log("Error Occured");
                   }
        });
       
        series.addCallback(function(response){
            //console.debug("Also got a successful server response: " + response.series['seriesA']);
            return response;
        });
I can see response data object in load function as


series -> {object with 2 items}
seriesB -> [array with 3 slots]
0 : 201
1 : 202
2 : 203
seriesA -> [array with 3 slots]
0 : 101
1 : 102
2 : 103

But I cant see response object data out side of this call. how can I access this data out side of this call? I want to use this data in different function(s). Can some one help me please...

By default, dojo.xhr* calls

By default, dojo.xhr* calls are asynchronous operations, so you will likely have to create a callback function that can be called from the load listener:
function handleResult(data){
    //Do something with the data here.
}
dojo.xhrGet({
           url: "actions/seriesBuilder.jsp",
           handleAs: "json",
           timeout: 5000,
           load: function(response, ioArgs) {
                    console.log(response);
 
                   handleResult(response);
                 },
            error: function(response, ioArgs) {
                      console.log("Error Occured");
                   }
        });

Thanks. Thats helped.

Thanks. Thats helped.