jQuery之ajax技术的详细介绍(4)


<!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=gb2312" />
<title>Post</title>
<script type="text/javascript" src="https://www.jb51.net/JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="https://www.jb51.net/JS/Post.js"></script>
<style type="text/css">
body{ padding:20px 80px; font-size:14px; }
#login{ width:240px; height:160px; margin:10px 0; padding:8px; border:solid 1px #777; font-size:13px; }
#login h4{ color:#666; margin:5px 0; font-size:18px; }
#login span{ font-size:15px; line-height:40px; font-weight:700; }
input,button{ margin:15px 0 0 0; line-height:14px;  }
input{ height:15px; }
</style>
</head>
<body>
<div>
 <h4>用户登录</h4>
 Username:<input />
    <br />
    Password:<input type="password" />
    <br />
    <button>Submit</button>
</div>
</body>
</html>


Post.js 

复制代码 代码如下:


$(document).ready(function(){
 $("#submit").click(function(){
  $.post("http://localhost:2154/Web/Login.aspx",
  {
   username : $("input[name='username']").val(),
   password : $("input[name='password']").val()
  },
  function(data){
   $("#login").html(data);
  });
 });
});


Login.aspx 

复制代码 代码如下:


<%@ Page Language="C#" %>
<span>欢迎你&nbsp;&nbsp;<font color="red"><%= Request.Form["username"] %></font>
<br />
你的身份是&nbsp;&nbsp;<font color="red">管理员</font>
<br />
&nbsp;&nbsp;<button>修改资料</button>
&nbsp;&nbsp;<button>注销登录</button>
</span>


7:$.getJSON()方法
var xmlReq = $.getJSON(url, [data], [callback]);

复制代码 代码如下:


<!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>getJSON</title>
<script type="text/javascript" src="https://www.jb51.net/JS/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="https://www.jb51.net/JS/getJSON.js"></script>
<style type="text/css">
body{ padding:20px; }
#peoples{ background:#999; border:solid 2px #333; width:300px; }
#peoples td{ padding:5px; }
#peoples thead{ background:#555; color:#FFF; font-weight:700; font-size:16px; }
#peoples tbody{ font-size:13px;background:#fff; }
</style>
</head>
<body>
<table cellspacing="1">
<thead>
<tr><td>Name</td><td>Age</td><td>Sex</td></tr>
</thead>
<tbody></tbody>
</table>
</body>
</html>


getJSON.js 

复制代码 代码如下:


$(document).ready(function(){
 /* 异步请求,载入 JSON 数据 */      
 $.getJSON("http://localhost:2154/Web/PeopleList.aspx",
  function(data){  
   /* 遍历请求结果 */
   $.each(data,
    function(index, p){
     var html = "<tr><td>" + p.name + "</td><td>" + p.age +
     "</td><td>" + (p.isMale ? "male" : "female") + "</td></tr>"
     $("#peoples>tbody").append(html);
    });
  });
});


PeopleList.aspx 

复制代码 代码如下:


<%@ Page Language="C#" %>
[{
 "name" : "David li",
 "age" : 61,
 "isMale" : true
},{
 "name" : "Michael Clinton",
 "age" : 53,
 "isMale" : true
},{
 "name" : "Brook Ann",
 "age" : 23,
 "isMale" : false
},{
 "name" : "Mary Johnson",
 "age" : 35,
 "isMale" : false
},{
 "name" : "Elizabeth Jones",
 "age" : 33,
 "isMale" : false
},{
 "name" : "James Smith",
 "age" : 25,
 "isMale" : true
}]


8:$.getScript()方法
var xmlReq = $.getScript(url, [callback]);

复制代码 代码如下:

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/wdggxs.html