PDA

View Full Version : Ajax Question.



chio1
28 Jan 2011, 6:16 AM
Hi ,
I'm trying to change my function:



getData: function(id) {
var context = 'Text';
return context;
},
to use service to grab data:



getData: function(id ) {
var context;
var processRequest = function(response) {
context = response.responseText;
};

Ext.Ajax.request({
url: 'Data/Read',
success: processRequest,
params: { id : id }
});

return context;
},
i have problem, context variable is empty (Request is made and service returning correct data) , what should i do to wait for response from ajax call and then return context value ?

jay@moduscreate.com
28 Jan 2011, 11:12 AM
Your problem is that you're not thinking asynchronously. the ajax request will allow getData to finish execution. your success method should be on the same object that getData lives.