在extjs商店中使用代理从Web api服务获取数据的问题

时间:2013-12-26 12:10:36

标签: javascript web-services extjs

当我尝试在我的extjs应用程序中使用Web API服务时,它给出了一个关于无效的HTTP状态代码500 的错误。任何人都可以告诉我为什么它给我这个错误。我的商店代码如下:

Ext.define(`Demo.store.Users`, {
    extend: `Ext.data.Store`,
    model: `Demo.model.User`,
    autoLoad: true,
    proxy: {
        type: `rest`,
        url : `http://localhost:50893/Api/EmployeeService`,

        reader: {
            type: `json`
        }
    }

});

错误:

OPTIONS http://localhost:50893/Api/EmployeeService?_dc=1388125117941&page=1&start=0&limit=25 500 (Internal Server Error) 
Ext.define.request Connection.js?_dc=1388125117581:358
Ext.define.doRequest Ajax.js?_dc=1388125117534:271
Ext.define.read Server.js?_dc=1388125117566:198
Ext.define.load AbstractStore.js?_dc=1388125117034:869
Base.implement.callParent ext-debug.js:4263
Ext.define.load Store.js?_dc=1388125117503:1552
(anonymous function) ext-debug.js:2085

OPTIONS http://localhost:50893/Api/EmployeeService?_dc=1388125117941&page=1&start=0&limit=25 Invalid HTTP status code 500 
Ext.define.request Connection.js?_dc=1388125117581:358
Ext.define.doRequest Ajax.js?_dc=1388125117534:271
Ext.define.read Server.js?_dc=1388125117566:198
Ext.define.load AbstractStore.js?_dc=1388125117034:869
Base.implement.callParent ext-debug.js:4263
Ext.define.load Store.js?_dc=1388125117503:1552
(anonymous function) ext-debug.js:2085

XMLHttpRequest cannot load http://localhost:50893/Api/EmployeeService?_dc=1388125117941&page=1&start=0&limit=25. Invalid HTTP status code 500 

提前致谢

2 个答案:

答案 0 :(得分:0)

也许......

默认情况下,商店使用GET方法发出请求,因此参数通过url传输,将商店配置更改为使用方法POST。

在内部代理配置中输入:

actionMethods:{
    create: 'POST',
    read: 'POST',
    update: 'POST',
    destroy: 'POST'
}

答案 1 :(得分:0)

最后我解决了我的问题...这是跨域问题而不是“休息”我使用“jsonp”作为请求类型。喜欢:

Ext.define('CLG.store.Employee', {
    extend: 'Ext.data.Store',
     model: 'CLG.model.Employee',

        autoLoad: true,

        proxy: {
            type: 'jsonp',
            url: 'http://localhost:50893/Api/EmployeeService',

            reader: {
                type: 'json'

            }

        }


}); 


只看到链接: ExtJs 4 - cross domain policy