2011-05-10 73 views
1

我有以下問題:我有一個Ext.data.JsonStore填充組合框。我得到一個loadexception 有時。我可以一次又一次刷新組合框,但遲早我會得到一個異常。因此,爲了檢查超時問題,我在服務器上添加了一個延遲,現在我總是得到異常。的代碼:JsonStore隨機拋出loadexception <i></i>

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

組合框:

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

根據提琴手

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

JSON的數據現在用7.5秒延時我得到一個異常的客戶端時,數據應該到達客戶端。沒有延遲,我隨機獲得例外。這個異常看到了Json數據,但是我得到的唯一描述是'語法錯誤',這沒有幫助。

我已經剝除了除窗體和商店/組合框之外的所有內容,它仍然會發生。正如您所看到的,我提供了模擬數據,因此數據庫甚至無法訪問。這讓我瘋狂!

我真的很感謝任何幫助,我一直在工作和關閉這個三天!爲了記錄,我使用Internet Explorer版本8.0.7600.16385,但它也發生在Chromium上。

更新 該錯誤沒有顯示在Firefox中,所以我不能使用控制檯。

從異常的幾個PARAMS
極限:25
查詢: 「」
開始:0
reader.ef.length:2
jsonData.rows [0] .ID:1
jsonData .rows [0] .Titel: 「IkBentitel」
reader.meta.fields [0]。名稱: 「ID」
reader.meta.fields [1]。名稱: 「影片名稱」
reader.meta.idProperty :「Id」
reader.meta.totalProperty:「r ecords「
reader.meta.url」/ Hour/ListTickets「

如果需要更多信息,請讓我知道。我還向異常處理程序添加了「args」,狀態爲200.它使我越來越困惑......

回答

1

而不是捕獲loadexception,請從商店中捕獲更通用的exceptionloadexception已棄用。在您的exception處理程序中,console.log其參數並使用內容更新您的問題。那會給我們更多關於爲什麼DataProxy拋出異常的信息。在exception事件PARAMS

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

細節在DataProxy event docs

編輯:我把錯誤的參數在我的代碼示例中,對不起!

檢查異常事件的參數type。這是一個字符串,我的猜測是它的值是remote--這意味着你得到了有效的HTTP響應(代碼200,就像你說的),但是讀者已經確定它包含來自服務器的錯誤。嘗試將"success": true添加到您的JSON響應中,並查看是否可以解決此問題。

如果typeresponse和你的HTTP響應不是400或500,然後將讀卡器已經確定響應不符合它的需要(例如,它缺少idPropertysuccessProperty它的格式希望)。

+0

我在異常處理程序中添加了'args',並且我得到的狀態是200.當我使用Firefox時,不會拋出異常,它在此處完美工作。 – Paul77 2011-05-11 07:44:46

相關問題