尝试捕获 302 状态 EXT js

发布于 2024-10-16 19:36:50 字数 1375 浏览 2 评论 0原文

我是 EXTJS 的新手,有一个问题, 这是我的商店

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

如果我使用 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 有一个特定的回调?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

廻憶裏菂餘溫 2024-10-23 19:36:50

看来你过于复杂了:

  • 200是成功之一,
  • 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' }
} );

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' }
} );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文