Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trying to catch 302 status EXT js

I'm 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 reload store by id someStore.reload({params:{someId:someId}});

it works normaly if I use Ext.data.HttpProxy, but I need to catch 302 and to do something handling 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 also

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 the response with data I need, but store doesn't reloads with the data.. May be JsonStore has a specific callback?

like image 889
Sergey Avatar asked Nov 05 '22 03:11

Sergey


1 Answers

It seems like you overcomplicated:

  • 200 is one of susscess
  • 302 is one of failure
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' }
} );
like image 114
bensiu Avatar answered Nov 20 '22 13:11

bensiu