简体   繁体   中英

XML parse to HTML with jQuery

I have some little problem with my scripts. I want to parse xml file with some data elements to my html file. So I try to use jQuery but it doesn't work. Can you help me?

This is my xlm file:

<?xml version="2.0"?>
<choices xml:lang="PL">
    <complete>Wskazówka</complete>
    <temperature>300 stopni celcjusza</temperature>
</choices>

This is my jQuery code:

$(document).ready(function () {
    $.get('../data/content_data.xml', function(data) {
       var complete = $(data).find('complete').text();
       var temperature = $(data).find('temperature').text();

       $('div.menu_circle').text(complete + "|" + temperature);
    });
});

I haven't tried this myself, but maybe it helps:

http://www.switchonthecode.com/tutorials/xml-parsing-with-jquery

The issue is how try to output your variables. Try to append your variables to your element.

$(complete + "|" + temperature).appendTo('div.menu_circle');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM