【问题标题】:ExtJS GET action to store returns 500 in FireFox用于存储的 ExtJS GET 操作在 FireFox 中返回 500
【发布时间】:2015-12-18 08:48:12
【问题描述】:

在从 Web API GET 请求加载数据时,我从 FireFox 获得了最奇怪的行为,而其他浏览器却完美地做到了这一点。以下是我使用 Firefox 时 Fiddler 可以告诉我的内容:

  3817  500 HTTP    localhost:52543 /api/Tasks/Get?_dc=1442848131483&page=1&start=0&limit=25    5 403   private application/xml; charset=utf-8  firefox:138020  

相同的操作,其他浏览器(Chrome):

3954   200  HTTP    localhost:52543 /api/Tasks/Get?_dc=1442848159073&page=1&start=0&limit=25    1 508   no-cache; Expires: -1   application/json; charset=utf-8 chrome:2808         

我无法捕获 Application_Error 中的错误,也无法在客户端的异常侦听器中收到错误,因此我怀疑在将结果返回给客户端和客户端处理结果之间出现了问题,但我完全不知道问题可能出在哪里。

这是商店定义:

Ext.define('SchedulerApp.store.UnplannedTaskStore', {
extend: 'Ext.data.Store',
model: 'UnplannedTask',
autosync: false,
autoLoad: true,
proxy: {
    type: 'rest',
    api: {
        read: '/api/Tasks/Get',
        add: '/api/Tasks/Add',
        update: '/api/Tasks/Update',
        destroy: '/api/Tasks/Destroy'
    },
    actionMethods: {
        create: 'POST',
        read: 'GET',
        update: 'POST',
        destroy: 'POST'
    },
    reader: {
        type: 'json',
        rootProperty: 'data',
        totalProperty: 'total'
    },
    writer: {
        type: 'json',
        writeAllFields: true
    }
},
listeners: {
    load: function (sender, node, records) {
    },
    exception: function (proxy, response, options) {
        Ext.MessageBox.alert('Error', response.status + ": " + response.statusText);
    }
}

});

和模型:

Ext.define('UnplannedTask', {
extend: 'Ext.data.Model',
fields: [
    { name: 'Importance', type: 'float' },
    { name: 'Category', type: 'string' },
    { name: 'TaskNo', type: 'float' }
]

});

这就是我在 Web API 中所拥有的:

[System.Web.Http.HttpGet]
    public async Task<dynamic> Get(string page, string start, string limit)
    {
        // Get items from database with request information from the Kendo Grid Control
        PagingResult<TaskViewModel> tasks = await this.Worker.GetPagedTasksAsync(int.Parse(page), int.Parse(limit), null, null);

        // Map them to store objects
        var convertedTasks = new SchedulerTasksViewModel()
        {
            total = tasks.Count,
            data = tasks.Items.Select(x => new SchedulerTask()
            {
                Importance = x.Importance,
                Category = x.Category,
                TaskNo = x.TaskNumber
            }).ToArray()
        };

        var response = Request.CreateResponse(HttpStatusCode.OK, convertedTasks);
        return response;
    }

可能是浏览器问题还是我在服务器端遗漏了什么?

【问题讨论】:

    标签: javascript extjs asp.net-web-api store


    【解决方案1】:

    我想详细说明一下。 XML 序列化程序抛出错误;您看不到详细信息,因为 IIS 不会将它们发送到前面。

    我建议您修改所有 API 调用,以便它们也可以与 XML 一起使用 - 即使您的前端不使用 XML。如果您可以在新的浏览器选项卡中打开 API 调用,并且 XML 序列化程序不会用序列化错误掩盖代码错误,那么调试起来会容易得多。

    要查看错误消息,您必须允许您的开发 IIS 将错误置于最前面:

    1. 打开 IIS7 管理器
    2. 选择网站并在其功能视图中双击“错误页面”。
    3. 右键单击并选择“编辑功能设置...”或从“操作”窗格(在右侧)中选择相同
    4. 选择“详细错误”单选按钮并单击确定

    (Source)

    我最好的猜测是你只需要用[DataContract][DataContractAttribute][DataMemberAttribute] 来装饰一些类型或属性。错误信息会告诉你哪些以及如何装饰。

    另外一件事:如果您使用多个 Ajax 请求,我建议您在 Ajax 代理上定义一个覆盖。这样你就不会忘记一个:

    Ext.define("MyApp.override.Ajax", {
        override:'Ext.data.proxy.Ajax',
        headers:{'Accept':'application/json'}
    });
    

    【讨论】:

      【解决方案2】:

      尝试将此标头添加到您的代理:

      headers: {'Content-Type': "application/json" }
      

      【讨论】:

      • 砰!当场,你是当天的英雄!好东西!
      猜你喜欢
      • 1970-01-01
      • 2020-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-20
      • 1970-01-01
      相关资源
      最近更新 更多