PDA

View Full Version : alert data outside ajax



azmen01
2 Jul 2012, 3:02 AM
Hi, (sorry for my english...)

i have a problem... i hae a function who i get an "ajax" data.... this data i write in an array!!
<<<<this works>>>>

but how i can "alert" this array outside from the "ajax-function"
????

- any ideas -


Ext.define('SaherdData', { singleton: true,
fields: []
});

Ext.Ajax.request({
url: 'benchmark/ajax_getStandorte.php',
success: function (result, request) {

var jsonData = Ext.decode(result.responseText);
for (data in jsonData) {
SaherdData.fields.push(jsonData[data].standort);
}

// HERE IT WORKS!!!!
//alert(SaherdData.fields);

}
});

// AND HERE NOT!!!!
alert(SaherdData.fields);

Izhaki
2 Jul 2012, 3:12 AM
The ajax request is asynchronies - the success function is called via a callback once the server respond, and not inline with the main execution code.

What exactly you are trying to do? Because if it is just a matter of having a more organised code that you can provide success with a local object method.

azmen01
2 Jul 2012, 3:40 AM
i will create a dynamic line chart! ...at first i will initialize the "fields" from json.Store!!


var store = Ext.create('Ext.data.JsonStore', {
fields: myfields,
data: mydata
});

"myfields" and "mydata" i will GET with ajax!

what is the way to do this? - or are there a better way??