Jquery之Ajax

来源:互联网 发布:做效果图的软件 编辑:程序博客网 时间:2024/06/06 03:13

一、JqueryAjax.aspx代码

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JqueryAjax.aspx.cs" Inherits="WebApp.JqueryAjax" %><!DOCTYPE html><html xmlns="http://www.w3.org/1999/xhtml"><head runat="server">    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />    <title></title>    <script src="../Js/jquery-1.7.1.js"></script>    <script type="text/javascript">        $(function () {            $("#btnGet").click(function () {                $.get("GetDate.ashx", { "name": "lisi", "pwd": "123" }, function (data) {                    alert(data);                });            });            $("#btnPost").click(function () {                $.post("GetDate.ashx", { "name": "lisi", "pwd": "123" }, function (data) {                    alert(data);                });            });            $("#btnAjax").click(function () {                $.ajax({                    type: "POST",                    url: "GetDate.ashx",                    data: "name=John&location=Boston",                    success: function (msg) {                        alert("Data Saved: " + msg);                    }                });            });        });    </script></head><body>    <form id="form1" runat="server">        <div>            <input type="button" value="GET获取数据" id="btnGet" />            <input type="button" value="POST获取数据" id="btnPost" />            <input type="button" value="AJAX获取数据" id="btnAjax" />        </div>    </form></body></html>
二、GetDate.ashx代码
using System;using System.Collections.Generic;using System.Linq;using System.Web;namespace WebApp{    /// <summary>    /// GetDate 的摘要说明    /// </summary>    public class GetDate : IHttpHandler    {        public void ProcessRequest(HttpContext context)        {            context.Response.ContentType = "text/plain";            context.Response.Write(context.Request["name"]);        }        public bool IsReusable        {            get            {                return false;            }        }    }}
三、效果演示


原创粉丝点击