zoukankan      html  css  js  c++  java
  • JQuery[13] Ajax的简单应用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <title>Ajax</title>
        <script src="../Scripts/jquery-1.4.1.js" type="text/javascript"></script>
        <script type="text/javascript">
            $(function () {
                //$.get / $.post内部均调用$.ajax
    
                //无参数ajax请求
                $("#btnGetTime").click(function () {
                    $.post("Ajax14-1.ashx", function (Returns, Status) {
                        if (Status == "success")
                            $("#txtTime").val(Returns);
                        else
                            alert("请求失败");
                    });
                });
    
                //有参数
                $("#btnInput").click(function () {
                    $.post("Ajax14-2.ashx", { "input": $("#txtInput").val() }, function (Returns, Status) {
                        if (Status == "success")
                            alert(Returns);
                        else
                            alert("请求失败");
                    });
                });
            });
        </script>
    </head>
    <body>
        <input id="txtTime" type="text" readonly="readonly" />
        <input id="btnGetTime" type="button" value="获得时间" />
    
        <input id="txtInput" type="text" />
        <input id="btnInput" type="button" value="发送字符串" />
    </body>
    </html>
    

      Ajax14-1.ashx Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace ImitationBaiduPostBar.JQuery
    {
    	/// <summary>
    	/// Ajax14 的摘要说明
    	/// </summary>
    	public class Ajax14 : IHttpHandler
    	{
    
    		public void ProcessRequest(HttpContext context)
    		{
    			context.Response.ContentType = "text/plain";
    			//context.Response.Write("Hello World");
    			context.Response.Write(DateTime.Now.ToString());
    		}
    
    		public bool IsReusable
    		{
    			get
    			{
    				return false;
    			}
    		}
    	}
    }
    

      Ajax14-2.ashx Code:

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    
    namespace ImitationBaiduPostBar.JQuery
    {
    	/// <summary>
    	/// Ajax14_2 的摘要说明
    	/// </summary>
    	public class Ajax14_2 : IHttpHandler
    	{
    
    		public void ProcessRequest(HttpContext context)
    		{
    			context.Response.ContentType = "text/plain";
    			//context.Response.Write("Hello World");
    			context.Response.Write(string.Format("你输入了:{0}",
    				context.Request.Form["input"]));
    		}
    
    		public bool IsReusable
    		{
    			get
    			{
    				return false;
    			}
    		}
    	}
    }
    

      

    My New Blog : http://blog.fdlife.info/ The more you know, the less you believe.
  • 相关阅读:
    Java反射【三、方法的反射】
    Java反射【二、Class类的使用】
    Java反射【一、概述】
    MySql学习笔记【四、数据相关操作】
    MySql学习笔记【三、表相关操作】
    MySql学习笔记【二、库相关操作】
    MySQL 表查询
    MySQL 表之间的关系
    MySQL 数据类型
    数据库概念 MySQL语法
  • 原文地址:https://www.cnblogs.com/ForDream/p/2137711.html
Copyright © 2011-2022 走看看