I have a problem with loading my XML properly. If I have more than one chat-tag element in my XMl, it will not load anything from it. But then I have just one, it works fine. Any ideas why?
Here is my code:
My XML:
I have a problem with loading my XML properly. If I have more than one chat-tag element in my XMl, it will not load anything from it. But then I have just one, it works fine. Any ideas why?
Here is my code:
My XML:
The root element in your XML is not well-formed. Have you tried to validate it?
I edited your XML file to this:
<?xml version="1.0" standalone="yes" ?>
<chat>
<message>
<username>Mon</username>
<msg>Hi son!</msg>
</message>
<message>
<username>Lund</username>
<msg>Hi mom!</msg>
</message>
</chat>
And your JavaScript function to this:
function loadXML() {
var lix = '<li class="box pre-post">';
$.ajax({
type: 'GET',
url: 'posts.xml',
datatype: 'xml',
success: function(data) {
$('.posts').children().remove();
$(data).find('message').each(function() {
var info = lix + $(this).find('username').text() + $(this).find('msg').text() + '</li>';
$('.posts').prepend(info);
});
}
});
}
And it seems to work