zoukankan      html  css  js  c++  java
  • 019-JQuery(Ajax异步请求)

    使用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     }
  • 相关阅读:
    Php扩展--protocolbuffers消息打包
    Php扩展--seasLog日志扩展安装
    PHP系统编程--03.PHP进程信号处理
    PHP系统编程--01.多进程与多线程
    PHP系统编程--02.PHP守护进程化
    linux shell 之if-------用if做判断
    Connection:Keep-alive
    Http报头Accept与Content-Type的区别
    json解析
    JSON-lib框架,转换JSON、XML不再困难
  • 原文地址:https://www.cnblogs.com/ninghongkun/p/6345121.html
Copyright © 2011-2022 走看看