PDA

View Full Version : Small understanding-Problem with AJAX / TaskMgr communication



tiberian
2 Nov 2009, 2:57 PM
Hi everybody,

maybe it's just a little thing, but i don't get the idea. My Goal is to develop a very simple Ext.data.Store - which simply implements a getValue() Method.

My.AjaxReader = Ext.extend(Ext.util.Observable,{
constructor: function () {..}

getValue: function () {
Ext.Ajax.request({
url: 'foo.php',
success: function() { this.value = respond.of.ajax; }),
params: { foo: 'bar' }
});
return this.value;
}
});
This store loads the data via ajax. There will be more stores, which load data from an array, or a xml-file (just like Ext.data.*). They all will have the method getValue() - so in an other Object i can use whatever store i want.


ElementCreator = Ext.extend(Ext.util.Observable,{
init: function() {
this.loader = new My.AjaxReader();
Ext.TaskMgr.start( {
task: function() { this.value = this.loader.getValue(); }
delay : 3000
});
}
});
(This is just kind of pseudo-code)
Now my problem is hard to describe, but how do i handle the callbacks? When ElementCreator (better: the TaskMgr) fetches the data via this.loader.getValue(), the ajax-request begins, but immediately the function returns.
How do i get this.loader.getValue(); to return the value when the load succeeded but not before?

Hope, you understand what i mean? :(

Thank you very much for your help and patience

tubamanu
2 Nov 2009, 3:08 PM
u have to wait for your serverresponse if i understand your problem right.....


Ext.Ajax.request({
url : 'yourURL.php'
success: function(objServerResponse){
alert(objServerResponse.responseText);
}
});