PDA

View Full Version : Ext.Ajax.request - callback to call another method



romerve
7 May 2012, 11:06 AM
Hello,

I have the following method in my controller:


requestSearch: function(needleStack) {

Ext.Ajax.request({
url: './index.php/sts/search',
method: 'POST',
params: {
query: needleStack
},
callback: function( success ) {
if ( success )
this.displayResults(MyResults);
else
this.displayErros(MyErrors);
}
});
}


All i am trying to do is to call other methods within the same controller, but it seems that i can no longer use "this" once the request is made. In a previous step in the process i have another method that makes calls to other methods within the same controller using "this.", but once i make the Ajax.request, "this" just returns the DOMWindow.

Is there anyway i can make calls to methods within the controller after i have an Ajax.request?

Thanks.

Tim Toady
7 May 2012, 12:02 PM
Ext.Ajax.request can also take a scope property. Just include scope: this

An alternative is to create a reference to the controller prior to calling the ajax request. You will then have access to that variable from within your callback.

romerve
7 May 2012, 12:25 PM
Ext.Ajax.request can also take a scope property. Just include scope: this

An alternative is to create a reference to the controller prior to calling the ajax request. You will then have access to that variable from within your callback.

Thank you.

datchayani
6 Nov 2012, 10:54 PM
i have include scope: this , inside ajax request. Its works, thank you