zoukankan      html  css  js  c++  java
  • jQuery读取数据

    1、jQuery读取JSON

    <!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 http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>jquery读取JSON</title>
    </head>
    <script type="text/javascript" src="jquery-3.2.1.js"></script>
    <script>
    $(function(){
    	$("#btn").click(function(){
    		$.getJSON("JSON/UserInfo.json",function(data){
    			var str="";
    			$.each(data,function( i,field){
    				$.each(	field,function(k,v){
    					str+=k+":"+v+"<br/>"
    					})	
    					str+="<br/>";
    				})
    				$("p").html(str);
    			})
    		})	
    	})
    </script>
    <body>
    <div>
    <div id="btn">
    <input type="button" value="读取JSON数据"  id="btn"/>
    </div>
    <p></p>
    </div>
    </body>
    </html>
    

    2、jQuery加载XML文档

    <!DOCTYPE html>
    <html>
    <head>
    	<title>使用jQuery加载XML文档</title>
    	<meta charset="utf-8">
    	<script type="text/javascript" src="jquery-3.2.1.js"></script>
    	<script type="text/javascript">
    		$(function(){
    			$("#getxml").click(function(){
    				$.ajax({
    					type:"get",
    					url:"5-3.xml",
    					dataType:"xml",
    					timeout:1000,
    					cache:false,//禁止缓存
    					success:function(data){
    						var frag=$("<ul/>");
    						$(data).find("student").each(function(){
                             var name=$(this).children("name");
                             var sex=$(this).children("sex");
                             var email=$(this).children("email");
                             name_value=name.text();
                             sex_value=sex.text();
                             email_value=email.text();
                             frag.append("<li>姓名:"+name_value+"性别:"+sex_value+"邮箱:"+email_value+"</li>");
    						});						
    			          frag.appendTo("#load");
    			          $("li").css("list-style-type","none");
    					}
    				});
    			})
    		})
    	</script>
    </head>
    <body>
    <input type="button" name="" id="getxml" value="加载xml">
    <div id="load"></div>
    </body>
    </html>
    

      

  • 相关阅读:
    yuv文件并行解析播放
    视频解析
    有意思的并查集讲解 收藏
    C++输入输出重载
    python 同步IO
    多线程与多进程的理解
    centos7 配置redis
    linux中的raid
    form表单系列中文件上传及预览
    centos7 安装swftools Apache_OpenOffice
  • 原文地址:https://www.cnblogs.com/qfdy123/p/8017382.html
Copyright © 2011-2022 走看看