2010-06-16 25 views
1

我使用ASP.NET和Jqgrid 3.7測試,在Firefox中它工作正常,但在IE中它不顯示網格中的任何行。Jqgrid 3.7不顯示在Internet Explorer中的行

來自web服務的響應

{"d": 
    {"__type":"jqGrid", 
    "total":"1", 
    "page":"1", 
    "records":"10", 
    "rows":[ 
     {"id":"180","cell":["180","Cultura"]}, 
     {"id":"61","cell":["61","Deporte"]}, 
     {"id":"68","cell":["68","Deporte"]}, 
     {"id":"5","cell":["5","Economía"]}, 
     {"id":"67","cell":["67","Economía"]}, 
     {"id":"76","cell":["76","Economía"]}, 
     {"id":"178","cell":["178","Economía"]}, 
     {"id":"4","cell":["4","Entrevista"]}, 
     {"id":"66","cell":["66","Entrevista"]}, 
     {"id":"78","cell":["78","Entrevista"]} 
    ] 
    } 
} 

和呼叫

myGrid = $("#list").jqGrid({ 
    url: 'ws/WsNoticias.asmx/jqObtenerTemas', 
    datatype: 'json', 
    mtype: 'GET', 
    loadBeforeSend: function(XMLHttpRequest) { 
     XMLHttpRequest.setRequestHeader("Content-Type", "application/json"); 
    }, 
    colNames: ['Id', 'Nombre'], 
    colModel: [ 
     {name: 'Id', index: 'Id', width: 20, align: 'left', editable: false}, 
     {name: 'Nombre', index: 'Nombre', width: 200, align: 'left', editable: false} 
    ], 
    rowNum: 10, 
    rowList: [5, 10, 200], 
    sortname: 'Nombre', 
    sortorder: "asc", 
    pager: $("#listp"), 
    viewrecords: true, 
    caption: '', 
    width: 600, 
    height: 250, 
    jsonReader: { 
     root: "d.rows", 
     page: "d.page", 
     total: "d.total", 
     records: "d.records" 
    } 
}); 

我看不出哪裏是問題... ...,與之前的版本3.6,並與

thegrid.addJSONData(JSON.parse(jsondata.responseText).d); 

而不是jsonReader它的工作原理。

回答

3

您應該首先在URL(首先使用http://或至少使用/開頭)中使用完整路徑。 Internet Explorer在許多與相關URL的情況下工作不正常。

還有一些小的一般性評論。您可以使用ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }而不是使用loadBeforeSend。其他一些默認值(見http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options)也可以刪除。

myGrid = $("#list").jqGrid({ 
    url: 'http://www.ok-soft-gmbh.com/jqGrid/Jqgrid37json.txt', 
    datatype: 'json', 
    mtype: 'GET', 
    ajaxGridOptions: { contentType: 'application/json; charset=utf-8' }, 
    colModel: [ 
     { name: 'Id', width: 20 }, 
     { name: 'Nombre', width: 200 } 
    ], 
    rowNum: 10, 
    rowList: [5, 10, 200], 
    sortname: 'Nombre', 
    sortorder: "asc", 
    pager: $("#listp"), 
    viewrecords: true, 
    width: 600, 
    height: 250, 
    jsonReader: { 
     root: "d.rows", 
     page: "d.page", 
     total: "d.total", 
     records: "d.records" 
    } 
}); 

而且可以將JSON數據減少到

{"d": 
    {"__type":"jqGrid", 
    "total":"1", 
    "page":"1", 
    "records":"10", 
    "rows":[ 
     ["180","Cultura"], 
     ["61","Deporte"], 
     ["68","Deporte"], 
     ["5","Economía"], 
     ["67","Economía"], 
     ["76","Economía"], 
     ["178","Economía"], 
     ["4","Entrevista"], 
     ["66","Entrevista"], 
     ["78","Entrevista"] 
    ] 
    } 
} 

,並在jsonReader的定義添加poperty細胞: 「」:

jsonReader: { 
    root: "d.rows", 
    page: "d.page", 
    total: "d.total", 
    cell: "", 
    records: "d.records" 
} 

您可以驗證http://www.ok-soft-gmbh.com/jqGrid/Jqgrid37.htmhttp://www.ok-soft-gmbh.com/jqGrid/Jqgrid37Comact.htm在所有標準Web瀏覽器中都可以正常工作。

+0

謝謝你,它像一個魅力。關鍵是: ajaxGridOptions:{contentType:'application/json; charset = utf-8'} – 2010-06-18 13:20:47

相關問題