my xml:
<stuffs>
<unit id="code">10</unit>
</stuffs>
my jquery ajax:
$.ajax({
type: "POST",
url: "xml/test.xml",
dataType: "xml",
success: function(xml) {
$(xml).find('stuffs').each(function(){
... the code are here ...
});
}
i’m trying to get the values from <unit> using the ID:
var unit = $(this).find('unit').attr('id');
var unitIdVal = $("#"+unit).text();
alert(unitIdVal);
but, nothing he found.
i dont know if is the same method of a comun jquery stuff’s
because i try to get the value direct using
var unitIdVal = $("#code").text();
but, nothing again.
ty
Your selector stuff above is wonky to say the least. You’re getting the ID off of an element and then getting that element once again by ID, all within a loop that does nothing for you…
Here’s what it needs to be:
I feel dirty even writing this though, and I hope that it’ll be used in a different context and this is merely illustrative.
Here’s what it should be. Note the lack of selecting the very same element that you got the ID off of:
Please read some helpful tutorials on XML parsing thoroughly.