Ajax基础

来源:互联网 发布:selfie city照相软件 编辑:程序博客网 时间:2024/06/05 21:02

Ajax本质是浏览器端的多线程

一、简单的用js实现Ajax


前段

    <script type="text/javascript">        window.onload = function () {            document.getElementById('btnGetTime').onclick = function () {                //1.向服务器请求 时间                 var xhr = new XMLHttpRequest();                xhr.open("get", "C02GetTime.ashx?Name='zj'", true);                xhr.onreadystatechange = function () {                    if (xhr.readyState == 4 && xhr.status == 200) {                        var res = xhr.responseText;                        alert(res);                    }                };                xhr.send(null);            }        }    </script>
后台
using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace Ajax{    /// <summary>    /// C02GetTime 的摘要说明    /// </summary>    public class C02GetTime : IHttpHandler    {        public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            context.Response.Write(DateTime.Now.ToString());        }        public bool IsReusable        {            get            {                return false;            }        }    }}



0 0