zoukankan      html  css  js  c++  java
  • Jquery与Json实现Ajax

    页面

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="JqueryAjax.aspx.cs" Inherits="JqueryAjax" %>

    <!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 runat="server">
        <title>无标题页</title>
        <script type="text/javascript" src="JS/jquery-1.3.1.js"></script>
        <script type="text/javascript">
            function getData(){
                $("#list").html("");
                $.getJSON("jsondata.ashx",
                {name:"test",age:20},
                function(json){
                    $.each(json,function(i){
                        $("#list").append("<li>name:"+json[i].name+"&nbsp;Age:"+json[i].age+"</li>")
                    });
                });
            }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
            <input id="Button1" type="button" value="获取数据" onclick="getData()" />
            <ul id="list"></ul>
        </form>
    </body>
    </html>

    处理页面jsondata.ashx

    <%@ WebHandler Language="C#" class="jsondata" %>

    using System;
    using System.Web;

    public class jsondata : IHttpHandler {
       
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            string data = "[{name:\"ants\",age:24},{name:\"lele\",age:23}]";//构建的json数据
            //下面的额两句是用来测试前台向此页面发出的查询字符
            string querystrname = context.Request.QueryString.GetValues("name")[0];//取查询字串的name值
            string querystage = context.Request.QueryString.GetValues("age")[0];//取查询字串的age值
            context.Response.Write(data);
        }
     
        public bool IsReusable {
            get {
                return false;
            }
        }

    }

  • 相关阅读:
    使用手机重量加速器
    改变 Pivot 的 HeaderTemplate
    页面构造函数和 Load 事件的执行次数
    给 ListBox 的 DataTemplate 模板中的 元素设置动画
    在ItemsControl 中,添加头部下拉更新
    (转) Unix 时间戳 与 .NET 时间转换
    图片保存到本机(链接)
    IsHitTestVisible="False" 的功能
    回到顶部按钮
    ssh访问服务器端visdom
  • 原文地址:https://www.cnblogs.com/YuanShuai/p/Joe.html
Copyright © 2011-2022 走看看