2011-02-08 34 views
5

我是新来EXTJS,并有一个问题, 这是我的商店试图赶上302状态的Ext JS

someStore = new Ext.data.JsonStore({ 

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

当我得到和Id我需要通过ID someStore.reload重装店({PARAMS:{someId:someId}});

它的工作原理normaly如果我使用Ext.data.HttpProxy,但我需要 赶上302,并做一些处理它,

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}); 
     } 
    } 
}; 

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);** 

问题是我得到的响应与我需要的数据,但存储不重新加载数据可能是JsonStore有特定的回调?

回答

2

好像你过于复杂:

  • 200 susscess
  • 302的一个是失败的一个
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' } 
});