I have this kind of ajax code repeated lot of places. How can I refactor this into a single method so it will still allow different behavior on success or failure.
Ext.Ajax.request({
    url : 'ajax.php' , 
    params : { action : 'getDate' },
    method: 'GET',
    success: function ( result, request ) { 
    Ext.MessageBox.alert('Success', 'Data return from the server: '+     result.responseText); 
    },
    failure: function ( result, request) {  Ext.MessageBox.alert('Failed', result.responseText); 
    } 
});
                
MyAjaxRequest = Ext.extend ( Ext.Ajax.request, {
     url : 'ajax.php' ,
     params : { action : 'getDate' },
     method: 'GET',
     success: function ( result, request ) {
        Ext.MessageBox.alert ('Success', 'Data return from the server: '+    result.responseText);
     },
     failure: function ( result, request) {
        Ext.MessageBox.alert('Failed', result.responseText);
      }
} ); 
by extending class (namespaces up to you) you still able to manipulate url, params, method, success, and failure. if not setup - defaults are there
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With