zoukankan      html  css  js  c++  java
  • AJAX

             AJAX  层层深入

    eg 1.==================================================

    html

    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title></title>
        <script type="text/javascript">
            function btnClick()     
            {   
                var xhr = new XMLHttpRequest();  //   1、创建XMLHttpRequest对象
    
               xhr.open("POST", "GetDate.ashx?ts=" + new Date(), true); // 2、设置open参数
               
                xhr.onreadystatechange = function ()   // 3、注册回调函数
                {  
                    if (xhr.readyState == 4)   //注意此处的readyState的大小写,写错了,就没效果了哦
                    {
    
                        if (xhr.status == 200)   //判断服务器返回的状态码是否为200,如果不是,则可能服务器出现了不测
                        { 
                            var res = xhr.responseText;//接收返回的效果
                            document.getElementById("Text1").value = res; //将返回的结果赋值
                        }
                    }
                }
               xhr.send(null);//  4、发送
    
                //  第4步改为 
               // xhr.send("txtName=ss&txtpwd=123");//参数名=参数值
    
    
            }
        </script>
    </head>
    <body>
    <input id="Text1" type="text"/>
     <input id="Button1" type="button" value="button"  onclick="btnClick();"/>
    </body>
    </html>
    View Code

    C#

     1 using System;
     2 using System.Collections.Generic;
     3 using System.Linq;
     4 using System.Web;
     5 
     6 namespace WebApplication3
     7 {
     8     /// <summary>
     9     /// GetDate 的摘要说明
    10     /// </summary>
    11     public class GetDate : IHttpHandler
    12     {
    13 
    14         public void ProcessRequest(HttpContext context)
    15         {
    16             context.Response.ContentType = "text/plain";
    17             string dd = DateTime.Now.ToString();
    18             context.Response.Write(dd);
    19             
    20         }
    21 
    22         public bool IsReusable
    23         {
    24             get
    25             {
    26                 return false;
    27             }
    28         }
    29     }
    30 }
    View Code

    效果图:

    =====================================================

    eg 2.==================================================

  • 相关阅读:
    js 获得多个同name 的input输入框的值
    推荐系统
    异常检测
    降维——PCA主成分分析
    无监督学习——降维
    无监督学习——K-means聚类
    支持向量机——内核
    支持向量机背后的数学
    支持向量机——Large Margin Classifier
    支持向量机
  • 原文地址:https://www.cnblogs.com/laopo/p/5472485.html
Copyright © 2011-2022 走看看