我有一个HTTP API,它(令人震惊的新技术)的反应在不同的错误设置不同的响应状态。
I have an http API which (shockingly new technique) reacts on different errors setting different response statuses.
现在的问题是 - 在使用Ext.data.Store一些XMLHtt prequest-内代理,什么是处理这种状态的最佳方法是什么?至于我能理解,load事件未通过身份直接,以及异常,而最后一个居然当接收到4 **状态不会甚至引发。
The question is - while using Ext.data.Store with some XMLHttpRequest-inside proxy, what is the best way to handle this statuses? As far as I can understand, "load" event does not pass status directly, as well as "exception", and the last one actually doesn't even trigger when 4** status is received.
所以,我可以从code XHR实例看到Ext.data.store是隐藏的,所以这个问题是也可以表述为什么是最好的ExtJS的做法来处理低级别XHR对象。
So, as I can see from code xhr instance is hidden from Ext.data.store, so the question is also can be stated as "What is best extjs practice to handle low-level xhr object".
没有的的异常的Ext.data.Store 的事件。相反,它是Ext.data.proxy.Server及其子类(如Ext.data.proxy.Ajax),该定义的异常事件。侦听器接收响应对象,其中包括HTTP状态。
There is no exception event on Ext.data.Store. Instead, it is Ext.data.proxy.Server and its sub-classes (like Ext.data.proxy.Ajax) that define an exception event. Listeners receive a response object which includes the http status.
根据设置的不同,你可以在商店的代理注册监听器,或者 - 如果你的存储使用一个模型 - 对模型的代理
Depending on your setup, you can register a listener on the store's proxy, or - if your store uses a model - on the model's proxy.
此测试设置为我工作在Chrome 14和FF 6:
This test setup worked for me on Chrome 14 and FF 6:
var store = Ext.create('Ext.data.Store', {
fields: [ 'field1', 'field2'],
proxy: {
type: 'ajax',
url: 'api/data.json',
reader: {
type: 'json',
root: 'data'
},
listeners: {
exception: function(proxy, exception, operation) {
console.log(response.status);
}
}
},
});
store.load();