jquery从xml获取数据到数组?

时间:2022-10-08 18:31:36

I'm learning about Jquery and I'm using JqGrid to manipulate my data. My grid fills perfectly with data from a php file 'admin_db', that "convert" its data into a xml file, like this:

我正在学习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;

I need to get 'id_alum' and 'name' into an array, but when I tried with this function to get data from 'name', nothing happens:

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

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

I hope that you can help me with my problem, I really need to get my data into an array. Thank you in advance =) (Sorry if my english is bad, I'm still learning)

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

1 个解决方案

#1


1  

try using:

尝试使用:

    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();
        })
    }

It's just a quick one... :)

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

#1


1  

try using:

尝试使用:

    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();
        })
    }

It's just a quick one... :)

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