ExtJS 4.2 - 加载存储时内部服务器错误500

时间:2016-05-31 08:28:36

标签: extjs model store

每次尝试加载商店时,我都会出现内部服务器500错误。我目前正在尝试连接到包含我需要的数据的API端点。这是我每次都会收到的错误(仅供参考,查看'接受'标题,它似乎是空的。我不知道我怎么能拥有application/json在那里正确连接到它):

enter image description here

我的商店设置如下:

Ext.define('EcommBackoffice.store.TierCapacity', {
  extend: 'Ext.data.Store',
  model: 'EcommBackoffice.model.TierCapacityModel',
  storeId: 'tier-capacity-id',
  autoLoad: true,
  sorters: [{
    property: 'name',
    direction: 'ASC'
  }],
  proxy: {
    type: 'rest',
    url: EcommBackoffice.Global.getAPIEndPoints().tier_capacity + '?siteCode=bgp88',
    reader: {
      type: 'json',
      root: ''
    },
    listeners: {
      exception: function(proxy, response, op) {
        if (response.status === 403 || response.status === 401) return; /*skip this exception handler and check App exception handler*/
        Ext.Msg.alert('ERROR', response.responseText + ' ' + response.statusText);
      }
    }
  }
});

我的模特是这样的:

Ext.define('EcommBackoffice.model.TierCapacityModel', {
  extend: 'Ext.data.Model',
  fields: [{
    name: 'id'
  }, {
    name: 'paymentOption',
    type: Ext.data.SortTypes.asUCString
  }, {
    name: 'tier',
    type: Ext.data.SortTypes.asUCString
  }, {
    name: 'media',
    type: Ext.data.SortTypes.asUCString
  }, {
    name: 'channels',
    type: Ext.data.SortTypes.asUCString
  }]
});

API包含以下内容:

[{
    "name": "DEBIT",
    "tiers": [{
        "name": "Default",
        "media": [{
            "name": "OFFICE",
            "channels": [{
                "name": "CHANNEL-001",
                "currentVolume": 0,
                "maxVolume": 0,
                "yesterdayVolume": 0
            }]
        }]
    }]
}]

此外,我对设置模型和商店有点不熟悉。我假设这是我错过的地方。我是否根据API响应正确构建模型?我试过阅读文档,但我仍然无法绕过它。

2 个答案:

答案 0 :(得分:1)

错误代码500告诉:

服务器遇到意外情况,导致无法完成请求。

我可以看到,在Java端处理代码时,您将获得NullPointerException。 因此,当发生意外异常时,会抛出Http 500错误代码,该代码会显示在浏览器中。此错误代码无法从客户端完成。

答案 1 :(得分:0)

错误500不是ExtJS问题。这是一个后端问题。您应该检查您使用的后端技术,并将这些技术添加到标签中以获得任何帮助。

  

检查'接受'标题,它似乎是空的。我不知道如何在那里使用application / json来正确连接它。

proxy: {
    headers: {
        Accept: 'application/json'
    },