e.vejar
e.vejar

Reputation: 43

jquery get data from xml into array?

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:

//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:

  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)

Upvotes: 0

Views: 513

Answers (1)

Sal
Sal

Reputation: 1655

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... :)

Upvotes: 1

Related Questions