JsonStore随机抛出loadexception <i> </i>

时间:2011-05-10 14:53:07

标签: extjs combobox jsonstore

我有以下问题:我有一个Ext.data.JsonStore,它填充了一个组合框。我得到了一个loadexception 有时候。我可以一次又一次刷新组合框,但迟早会得到一个例外。因此,为了检查超时问题,我在服务器上添加了一个延迟,现在我一直得到例外。代码:

JsonStore:

var ticketStore = new Ext.data.JsonStore({
    url:'/Hour/ListTickets',
    autodestroy:true,
    totalProperty:'records',
    idProperty:'Id',
    root:'rows',
    fields:[{name:'Id'},{name:'Titel'}]
});
ticketStore.on({'loadexception':{fn:storeLoadException,scope:this}});

ComboBox:

var ticketCombo = new Ext.form.ComboBox(
            {
                fieldLabel:'Ticket',
                hiddenName:'TicketId',
                store:ticketStore,
                width:300,
                valueField:'Id',
                minChars:2,
                displayField:'Titel',
                typeAhead:false,
                forceSelection:true,
                pageSize:25,
                triggerAction:'all',
                emptyText:'Selecteer een waarde...',
                selectOnFocus:true,
                valueNotFoundText:"nitchevo",
                value:1567,
                allowBlank: false
            }
        );

数据:

    try
    {
        IList<Dictionary<string, object>> returnValue = new List<Dictionary<string, object>>();

        returnValue.Add(new Dictionary<string, object>{ {"Id", 1}, {"Titel", "IkBenTitel"}});
        System.Threading.Thread.Sleep(7500);

        return returnValue;

    }
    catch (Exception e)
    {
        Console.WriteLine(e);
    }

从数据到Json的转换

public static JsonResult JSon(this IList<Dictionary<string, object>> list)
{
    var jsonData = new
    {
        records = list.Count,
        rows = list.ToArray()
    };
    JsonResult json = JsonHelper.Json(jsonData);
    return json;
}

根据Fiddler的Json数据

{"records":1,"rows":[{"Id":1,"Titel":"IkBenTitel"}]}

现在延迟7.5秒,当数据到达客户端时,我得到一个异常客户端。没有延迟,我随机获得异常。例外情况是Json数据,但我得到的唯一描述是“语法错误”,这没有用。

我已经剥离了除了表单和商店/组合框之外的所有内容的页面,它仍然会发生。如您所见,我提供了模拟数据,因此甚至无法访问数据库。这让我发疯了!

我真的很感激任何帮助,我一直在努力工作三天!为了记录,我使用的是Internet Explorer版本8.0.7600.16385,但它也发生在Chromium上。

更新 该错误未在Firefox中显示,因此我无法使用控制台。

例外的几个参数
限制:25
查询:“”
开始:0
reader.ef.length:2
jsonData.rows [0] .Id:1
jsonData.rows [0] .Titel:“IkBentitel”
reader.meta.fields [0] .name:“Id”
reader.meta.fields [1] .name:“Titel”
reader.meta.idProperty:“Id”
reader.meta.totalProperty:“记录”
reader.meta.url“/ Hour / ListTickets”

如果需要更多,请告诉我。我还在异常处理程序中添加了'args',状态为200.它让我越来越困惑......

1 个答案:

答案 0 :(得分:1)

不是捕获loadexception,而是从商店中捕获更通用的exception。不推荐使用loadexception。在exception处理程序中,console.log其参数并使用内容更新您的问题。这将为我们提供有关DataProxy抛出异常的原因的更多信息。

ticketStore.on('exception', function(proxy, type, action, options, response, args) {
    console.log(proxy, type, action, options, response, args);
});

exception事件参数的详细信息位于DataProxy event docs

编辑:我在代码示例中添加了错误的参数,抱歉!

检查异常事件的type参数。这是一个字符串,我的猜测是它的值是remote - 这意味着你得到了一个有效的HTTP响应(代码200,就像你说的那样),但是读者已经确定它包含来自服务器的错误。尝试将"success": true添加到您的JSON响应中,看看是否能解决它。

如果type的值为response且您的HTTP响应不是400或500,则读者已确定响应与其正在寻找的格式不匹配(例如,错过了它想要的idPropertysuccessProperty