jquery 读取xml

 1     <script type="text/javascript" src="jquery/jquery-1.11.3.min.js"></script>
 2     <script type="text/javascript">
 3         //var url = "http://www.w3school.com.cn/example/xmle/simple.xml";
 4         var url = "xml.xml"
 5         var breakfast_menu =new Array();
 6         var food = {};
 7         $(function () {
 8             $("#readXML").click(function(){
 9                 $.get(url,function(data){
10                     var xmlData = $(data);
11                     xmlData.find("food").each(function(i){
12                         food.name = $(this).children("name").text();
13                         food.price = $(this).children("price").text();
14                         food.description = $(this).children("description").text();
15                         food.calories = $(this).children("calories").text();
16                         $("#disply").append(food.name + "\n");
17 //                        breakfast_menu.push(food);
18                     })
19                 });
20            /*     for(var i = 0;i<breakfast_menu.length;i++){
21                     $("#disply").append(breakfast_menu[i].name + "\n");
22                 }*/
23             })
24         })
25     </script>

 

你可能感兴趣的:(jquery 读取xml)