为什么我从 jsp 页面获取的 xml 数据没有显示在 jqgrid 中?

发布于 2024-10-14 06:37:51 字数 3037 浏览 2 评论 0原文

我正在尝试从 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

看轻我的陪伴 2024-10-21 06:37:51

您可能应该在其他地方寻找问题的原因。

您如何在此处看到您发布的代码确实显示了数据。需要注意的是,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.

初相遇 2024-10-21 06:37:51

我在使用 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!

丶情人眼里出诗心の 2024-10-21 06:37:51

在 JQgrid 中添加 autoencode: true,

  jQuery("#list1").jqGrid({
            url:'server.jsp',
            datatype: "xml",
            autoencode: true,
            mtype: 'GET' ,

Add autoencode: true, in your JQgrid

  jQuery("#list1").jqGrid({
            url:'server.jsp',
            datatype: "xml",
            autoencode: true,
            mtype: 'GET' ,
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文