Trying to catch 302 status EXT js

I am new to EXTJs and have a problem, this is my store

someStore = new Ext.data.JsonStore({

    root: 'results',
    proxy: new My.HttpProxy({
        url: '/cityList',
        method: 'POST'
    }),
    fields: ['id','name']
});

when I get and Id, I need to reboot the storage by id someStore.reload ({PARAMS: {someId: someId}});

it works fine if I use Ext.data.HttpProxy, but I need to catch 302 and do something with it,

My.Ajax = {

    proxyRequest: function(o){
        this.cbOutSide = o.callback;
        o.callback = this.cb;
        Ext.Ajax.request(o);
    }...
    cb: function(options, success, response) {
            ....
      if (response.status == 200) {
          var resObj = Ext.util.JSON.decode(response.responseText);
          this.cbOutSide(resObj);
      }     
      if (response.status == 302) {
          Ext.Msg.show({title: '...',msg: 'Time OUT!', 
             buttons: Ext.Msg.OK, icon: Ext.MessageBox.ERROR});
      }  
   }
};  

and

My.HttpProxy = Ext.extend( Ext.data.HttpProxy, {

    doRequest : function(action, rs, params, reader, cb, scope, arg) {

....

if(this.useAjax){

        Ext.applyIf(o, this.conn);
        if (this.activeRequest[action]) {
        }
        this.activeRequest[action] = **My.Ajax.proxyRequest(o);**

the problem is that I get a response with the data that I need, but the storage does not reload with data. Maybe JsonStore has a specific callback?

+5
source share
1 answer

You seem too complicated:

  • 200 is one of susscess
  • 302 is one of the failures
My.Ajax = new Ext.Ajax.request ( {
   url: 'foo.php',
   success: function ( f, a ) {
      // a.response.status == 200, or 304 (not modified)
      var resObj = Ext.util.JSON.decode ( response.responseText );
      this.cbOutSide ( resObj ); 
   },
   failure: function ( f, a ) {
       if ( a.response.status == 302) {
           Ext.Msg.show ( { title: '...',msg: 'Time OUT!', 
                buttons: Ext.Msg.OK, icon: Ext.MessageBox.ERROR } );
       }
   },
   headers: {
       'my-header': 'foo'
   },
   params: { foo: 'bar' }
} );
+2
source

All Articles