Friday, August 28, 2009

[jQuery] AJAX: process the response XML

Hi All

I'm truggling with this for a while now, without succes. Here is the
test code:

$.ajax({
type: "GET",
url: url,
cache: false,
dataType: 'xml',
async: true,
complete: function(data, status) {
// get title name of the book element with id 'xyz'
}
}) ;

suppose the xml send from the server is

<?xml version="1.0" encoding="UTF-8"?>
<books>
<book id='abc'>
<title>Some Title</title>
</book>
<book id='xyz'>
<title>Other title</title>
</book>
</books>

So my question is: How do I get the title from the book element with
id 'xyz'
I've tried to parse data.responseXML or something like

var d = $(data) ;
d.find('#xyz').each(function() { ... }) ;

It would be great if I could do something like:

alert("TITLE IS " + $("#xyz", data.responseXML).text() );

Any suggestions ?
or maybe these a plugin that can help?

thnx a lot

No comments: