码迷,mamicode.com
首页 > Web开发 > 详细

ajax 第一节

时间:2015-11-29 21:02:55      阅读:158      评论:0      收藏:0      [点我收藏+]

标签:

<!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 src="js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript">

        $(function () {


            $("#btn").click(
                       function () {
                       

                           if (XMLHttpRequest) {


                               var xhr = new XMLHttpRequest();

                           }
                           else {

                               //ie  5 6 
xhr = new ActiveXObject("Microsoft.XMLHTTP"); } xhr.open("get", "handler1.ashx?r=1", true); xhr.send(); xhr.onreadystatechange = function () { if (xhr.readyState == 4) { if (xhr.status == 200) { $("#test1").val(xhr.responseText); } } } } ) }) </script> </head> <body> <input type="button" id="btn" value="ajax"/> <input type="text" id="test1" value="3" /> </body> </html>

 

一般处理程序 页 :

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace WebApplication2
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write(DateTime.Now.Millisecond);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}

 

ajax 第一节

标签:

原文地址:http://www.cnblogs.com/xh0626/p/5005265.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!