我試圖從jsp
響應中加載數據,這是JSON
使用JQGrid。JQGrid數據未加載JSON服務器響應
我的index.html
<pre>
<script type="text/javascript" src="jqgrid/src/i18n/grid.locale-en.js"></script>
<script type="text/javascript" src="jqgrid/src/grid.loader.js"></script>
<script type="text/javascript" src="jqgrid/js/jquery.jqGrid.min.js"></script>
</pre>
function getEmployeeDetails(){
jQuery("#list").jqGrid({
datatype: function(postdata) {
jQuery.ajax({
url: 'execute.jsp?command=command',
mtype:'POST',
datatype:"json",
colModel : [
{name:'amount', width:30, sortable:true, align:'center'},
{name:'age', width:40, sortable:false, align:'center'},
{name:'name', width:180, sortable:true, align:'left'},
{name:'total', width:380, sortable:true, align:'left'}
],
jsonReader : {
root: "key",
page: "currentpage",
total: "total",
records: "totalrecords",
repeatitems: true,
cell: "cell",
id: "id",
userdata: "userdata"
},
width: 700,
height: 200,
pager: '#pager',
sortorder: 'desc',
viewrecords: true,
caption: 'My first grid'
});
}
});
}
而且我execute.jsp代碼
**<pre>
response.setContentType("application/json");
response.getWriter().write(wr.toJSONString());
</pre>**
我JSON string
從Java對象生成。
{ "totalrecords":"20", "tota1":"10", "currentpage":"runCommand.jsp", "key":[ {"id":"1","cell":["12000","30","Myname","10000"]} ] }
數據未加載到表中。我嘗試的方式不同,我不能成功。總是表空來,並說加載.....請幫助我。這裏有什麼不對...
您不應該同時使用'grid.loader.js'和'jquery.jqGrid.min.js'。如果您需要調試jqGrid的JavaScript代碼,最好使用'jquery.jqGrid.src.js'而不是'jquery.jqGrid.min.js'(當然不要使用'grid.loader.js')。 – Oleg