jquery+调用xml json应用

2010-12-13 12:51:33 by 【6yang】, 140 visits, 收藏 | 返回

 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta charset="utf-8"/>
<title>jquery+调用xml json应用</title>
</head>
<style type="text/css">
.btnDialog01,
.btnDialog02{
 padding:12px 12px;
}
</style>
 
 
 
<body>
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript">

$(function() {
  //json格式
  /*{"player":{"url":"1111"},
   "debug":{"levels":"all","debugger":"debug"}
  }*/
   
   oData = {};
     url = "testjson.js";
    
     $.post(url, oData, function(json){
     alert(json.player.url);
   }, "json");
    
    
    
 $.getJSON(url, function(json) {
  $.each(json, function(i, item01) {
         alert(i);
   $.each(item01, function(j, item02) {
    alert(item01.levels);
   });
  });
 });
 
 
//get json格式
 $.getJSON("http://feeds.delicious.com/v2/json/popular?count=5&callback=?",
  function(data){
    var res = '';
    $.each(data, function(i,item){
   res = res + "<a href='" + item.u + "'>" + item.d + "</a><br/>"
   res = res + item.t + "<br/><br/>"
    });
    $("#display").append(res);
  }
 );
 
 
 /*jquery get xml;*/
 
 /*xml 格式
 <?xml version="1.0" encoding="gbk"?>
 <smartresult>
 <product type="ip">
 <ip>55.2.5.2</ip>
 <location>英国</location>
 <ip>55.2.5.8</ip>
 <location>美国</location>
 <ip>55.2.5.48</ip>
 <location>德国</location>
 </product>
 </smartresult>*/


 function loadXML(xmlpath){
  var xmlDoc = null;
  if (window.ActiveXObject){
   xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
  }else
  if (document.implementation && document.implementation.createDocument){
   xmlDoc = document.implementation.createDocument("","",null);
  }else{
   alert('Your browser cannot handle this script.');
  }
  xmlDoc.async = false;
  xmlDoc.load(xmlpath);
  return xmlDoc;
 } 
 oxml = loadXML("search.xml");
 //创建处理XML的对象,兼容多种浏览器
 

 var countryHtml;
 $(oxml).find("location").each(function(){
  countryHtml += '<option value="'+$(this).prev("ip").text()+'">'+$(this).text()+'</option>';
 })
 $(countryHtml).appendTo("#country");


 
});


 
</script>
 <div id="display"></div>
  <div><select id="country"></select></div>
</body>
</html>

分享到:
share

    图片原图

    loading

    loading