Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs ajax code refactor

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); 
    } 
});
like image 714
fastcodejava Avatar asked Feb 25 '23 06:02

fastcodejava


1 Answers

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

like image 61
bensiu Avatar answered Mar 08 '23 14:03

bensiu