为什么我从 jsp 页面获取的 xml 数据没有显示在 jqgrid 中?
我正在尝试从 jsp 页面将数据(以 xml 形式)加载到我的 jqgrid 中,但我不明白为什么我看不到网格内的数据。我尝试了一切,但仍然不起作用。
这是我的 html 页面:
<script type="text/javascript">
$(document).ready(function()
{
jQuery("#list1").jqGrid({
url:'server.jsp',
datatype: "xml",
mtype: 'GET' ,
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:75},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:10,
autowidth: true,
rowList:[10,20,30],
pager: jQuery('#pager1'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"XML Example"
}).navGrid('#pager1',{edit:false,add:false,del:false});
});
<table id="list1"></table>
<div id="pager1"></div>
这是我的 jsp 页面:
<%
response.setContentType("text/xml;charset=utf-8");
%>
<?xml version='1.0' encoding = 'utf-8'?>
<rows>
<page>1</page>
<total>5</total>
<records>5</records>
<row id='1'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
<row id='2'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
<row id='3'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
<row id='4'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
<row id='5'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
</rows>
我做错了什么?
I'm trying to load data (in xml form) into my jqgrid from a jsp page, but I can't understand why I'm not seeing the data inside the grid. I tried everything, but it's still not working.
This is my html page:
<script type="text/javascript">
$(document).ready(function()
{
jQuery("#list1").jqGrid({
url:'server.jsp',
datatype: "xml",
mtype: 'GET' ,
colNames:['Inv No','Date', 'Client', 'Amount','Tax','Total','Notes'],
colModel:[
{name:'id',index:'id', width:75},
{name:'invdate',index:'invdate', width:90},
{name:'name',index:'name', width:100},
{name:'amount',index:'amount', width:80, align:"right"},
{name:'tax',index:'tax', width:80, align:"right"},
{name:'total',index:'total', width:80,align:"right"},
{name:'note',index:'note', width:150, sortable:false}
],
rowNum:10,
autowidth: true,
rowList:[10,20,30],
pager: jQuery('#pager1'),
sortname: 'id',
viewrecords: true,
sortorder: "desc",
caption:"XML Example"
}).navGrid('#pager1',{edit:false,add:false,del:false});
});
<table id="list1"></table>
<div id="pager1"></div>
This is my jsp page:
<%
response.setContentType("text/xml;charset=utf-8");
%>
<?xml version='1.0' encoding = 'utf-8'?>
<rows>
<page>1</page>
<total>5</total>
<records>5</records>
<row id='1'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
<row id='2'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
<row id='3'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
<row id='4'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
<row id='5'>
<cell>1</cell>
<cell>2</cell>
<cell><![CDATA[eeeeeee]]></cell>
<cell>3</cell>
<cell>4</cell>
<cell>5</cell>
<cell><![CDATA[eeeeeee]]></cell>
</row>
</rows>
What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能应该在其他地方寻找问题的原因。
您如何在此处看到您发布的代码确实显示了数据。需要注意的是,
total
的值应该是页数而不是记录数,但 XML 数据看起来更像是虚拟数据。You should probably search for the reason of the problem somewhere else.
How you can see here the code which you posted do display the data. One remark only the value of
total
should be the number of pages and not the number of records, but the XML data looks more as a dummy data.我在使用 JSON 数据、jquery 1.5 和 jquery.validate.min.js 时遇到类似的问题。
jquery.validate.min.js 1.8 版本解决了这个问题!
I am having a similar issue using JSON data, jquery 1.5, and jquery.validate.min.js.
Version 1.8 of jquery.validate.min.js resolves this issue!
在 JQgrid 中添加 autoencode: true,
Add autoencode: true, in your JQgrid