【问题标题】:jquery get data from xml into array?jquery从xml获取数据到数组中?
【发布时间】:2011-12-08 06:09:24
【问题描述】:

我正在学习 Jquery,并且正在使用 JqGrid 来操作我的数据。 我的网格完美地填充了来自 php 文件 'admin_db' 的数据,将其数据“转换”为 xml 文件,如下所示:

//php file        
while($row = mysql_fetch_array($result,MYSQL_ASSOC)) {
        $s .= "<row id='". $row['id_alum']."'>";            
        $s .= "<cell>". $row['id_alum']."</cell>";
        $s .= "<cell>". $row['name']."</cell>";
        $s .= "</row>";
    }

        $s .= "</rows>"; 

        echo $s;

我需要将 'id_alum' 和 'name' 放入一个数组中,但是当我尝试使用此函数从 'name' 获取数据时,没有任何反应:

  type: "GET",  
  url: "admin_db.php",  
  dataType: "xml",      
  $(xml).find('name').each(function(){...} 

我希望你能帮助我解决我的问题,我真的需要将我的数据放入一个数组中。 提前谢谢你=) (对不起,如果我的英语不好,我还在学习)

【问题讨论】:

  • 您当前的代码查找名为“名称”的标签。由于您的所有标签都被命名为“单元格”,因此您必须在每行中查找第三个单元格才能获取数据

标签: php jquery xml jqgrid


【解决方案1】:

尝试使用:

    type: "GET",
    url: "admin_db.php",
    dataType: "xml",
    success: function(xml) {
        $(xml).find('row').each(function(){
            var id_alum = $(this).find('cell:eq(0)').text();
            var name = $(this).find('cell:eq(1)').text();
        })
    }

这只是一个快速... :)

【讨论】:

  • 谢谢!我马上试试!
  • $(function(){ url:'lista_bd.php', datatype: 'xml', mtype: 'GET', success: function(xml) { $(xml).find('row').each(function(){ var id_alum = $(this).find('cell:eq(0)').text(); var name = $(this).find('cell:eq(1)').text(); }} }); 这个函数不保存任何东西,所以当我尝试引用变量时,它们显示为空。任何帮助将不胜感激。
猜你喜欢
  • 2014-02-21
  • 2013-02-19
  • 1970-01-01
  • 2011-05-17
  • 1970-01-01
  • 1970-01-01
  • 2023-03-28
  • 1970-01-01
  • 2023-03-11
相关资源
最近更新 更多