Jimmy
Jimmy

Reputation: 35

Trying to find a way to load xml with ajax on a link click

What I'm trying to find a way to do is load some data from xml, and load it on a page dynamically with a click on a link. Is this possible? Is there anyway someone can point me in the right direction? Is it possible to make a link call a javascript function?

Upvotes: 1

Views: 73

Answers (1)

Harmen
Harmen

Reputation: 22438

To do this easily, you could use jQuery. It will auto-detect XML, but you can also force it:

$('#link').click(function(){
  $.ajax({
    url: 'yourXMLfile.xml',
    dataType: 'xml',
    success: function(data) {
      $(data).find('xmltag').each(function(i,el){
        alert( $(this).text() );
      });
    }
  });

  return false;
});

The code above will alert all text of all <xmltag> tags

Upvotes: 1

Related Questions