开发者

JsonStore throws loadexception <i>at random</i>

开发者 https://www.devze.com 2023-03-04 17:26 出处:网络
I have the following problem: I have an Ext.data.JsonStore which populates a combobox. I get a loadexception sometimes. I can refresh the combobox time after time but sooner or later I get an exceptio

I have the following problem: I have an Ext.data.JsonStore which populates a combobox. I get a loadexception sometimes. I can refresh the combobox time after time but sooner or later I get an exception. Therefore, to check for time-out problems, I added a delay on the server and now I get the exception all the time. The code:

The 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}});

The 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
            }
        );

The data:

    try
    {
        IList<Dictionary<string, object>> returnValue = new List<Dictionary<string开发者_JAVA百科, object>>();

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

        return returnValue;

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

The conversion from data to 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;
}

The Json-data according to Fiddler

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

Now with the 7.5 seconds delay I get an exception client-side when the data is supposed to arrive at the client. Without the delay I get the exception at random. The exception sees the Json data but the only description I get is 'Syntax error' which isn't helpful.

I have stripped the page of everything except the form and the store/combobox, it still happens. As you see I provide mock data so the database is not even accessed. It's driving me crazy!

I'd truly appreciate any help, I've been working on and off this for like three days! For the record, I use Internet Explorer version 8.0.7600.16385 but it also happens on Chromium.

Update The bug doesn't show up in Firefox so I can't use console.

A few params from the exception

limit: 25

query: ""

start: 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: "records"

reader.meta.url "/Hour/ListTickets"

If any more are required please let me know. I have also added 'args' to the exception handler and the status is 200. It puzzles me more and more...


Instead of catching loadexception, catch the more generic exception from the store. loadexception is deprecated. In your exception handler, console.log its parameters and update your question with the contents. That will give us more info on why the DataProxy is throwing the exception.

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

Details on the exception event params are in the DataProxy event docs.

EDIT: I put the wrong arguments in my code sample, sorry!

Check the type parameter of the exception event. It's a string and my guess is that its value is remote - meaning you got a valid HTTP response ( code 200, like you said ), but the reader has determined that it contains an error from the server. Try adding in "success": true to your JSON response and see if that solves it.

If the value of type is response and your HTTP response isn't a 400 or 500, then the reader has determined that the response doesn't match the format it's looking for (e.g. it's missing the idProperty or successProperty that it wants).

0

精彩评论

暂无评论...
验证码 换一张
取 消