首页 > Web开发 > 详细

019-JQuery(Ajax异步请求)

时间:2017-01-23 23:55:34      阅读:386      评论:0      收藏:0      [点我收藏+]

使用jquery完成异步操作

-》开发文档提供的异步API
url:请求地址
type:请求方式,主要是get、post
data:{}:请求的数据
dataType:返回值的类型,主要有xml、text、json、script、html
success:function(data){...}成功的回调函数(4,200)

GetTime.html

 1 <!DOCTYPE html>
 2 <html xmlns="http://www.w3.org/1999/xhtml">
 3 <head>
 4     <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 5     <title></title>
 6     <script src="js/jquery-1.7.1.min.js"></script>
 7     <script>
 8         $(function () {
 9             $(#btnGetTime).click(function () {
10                 $.ajax({
11                     url: GetTime.ashx,
12                     type: post,//‘get‘,
13                     data: {
14                         title: xlb
15                     },
16                     dataType: html,
17                     success: function (msg) {
18                         $(#showTime).html(msg);
19                     }
20                 });
21 
22                 //$.get(‘GetTime.ashx‘,
23                 //    ‘title=yg‘,
24                 //    function(msg) {
25                 //        $(‘#showTime‘).html(msg);
26                 //    }
27                 // );
28 
29             });
30         });
31     </script>
32 </head>
33 <body>
34     <input type="button" id="btnGetTime" value="获取时间" />
35     <div id="showTime"></div>
36 </body>
37 </html>

GetTime.ashx

 1     public class GetTime : IHttpHandler
 2     {
 3 
 4         public void ProcessRequest(HttpContext context)
 5         {
 6             context.Response.ContentType = "text/html";
 7 
 8             string title = context.Request["title"];
 9 
10             context.Response.Write("<h1>" + DateTime.Now.ToString() + "_" + title + "</h1>");
11         }
12 
13         public bool IsReusable
14         {
15             get
16             {
17                 return false;
18             }
19         }
20     }

 

019-JQuery(Ajax异步请求)

原文:http://www.cnblogs.com/ninghongkun/p/6345121.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!