Hi,
i need help with my code. I want to build a Ajax.request factory, so:
Code:
MyApp.ajax_request = function(config){
successfn = function(result, request){
jsonData = Ext.util.JSON.decode(result.responseText);
if(jsonData.success === true){
config.successfn; //important. here i want to run function passed in config.
}
else{
if(jsonData.error == 'TIMEOUT'){
Ext.Msg.show({
title: 'Błąd - ' + jsonData.error,
msg: jsonData.msg,
buttons: Ext.MessageBox.OK,
fn: function(){ window.location = '/' }
});
}
else if(jsonData.error == 'NOT_LOGGED'){
Ext.Msg.show({
title: 'Błąd - ' + jsonData.error,
msg: jsonData.msg,
buttons: Ext.MessageBox.OK,
fn: function(){ window.location = '/' }
});
}
else{
Ext.Msg.alert('Błąd - ' + jsonData.error, jsonData.msg);
}
}
}
failurefn = function(result, request){
Ext.Msg.alert('error', 'error msg');
}
Ext.Ajax.request({
url: config.url,
params: config.params,
success: successfn,
failure: failurefn
});
}
As I mentioned, I want to pass in config function which will be fired in success callback:
Code:
config = {
url: '/operators/new',
successfn: function(){
//some code to run, but never will. why?
},
params: {data: Ext.encode(nops)}
};
MyApp.ajax_request(config);
My question is how to pass function which will be trigered as is in my Ajax.request?