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;
            }
        }

    }

  • 相关阅读:
    使用git笔记
    linux 进程管理的一些命令使用
    [zz]XML DOM 教程
    [zz]std::string 和 c 的字符串
    [zz]grep 命令的使用
    [zz]XercesC++ 参考
    [zz]Windows WordPress本地安装教程
    今天调出来的关于cello的bug
    shell 编程的一些问题
    关于java中边界值校验的问题
  • 原文地址:https://www.cnblogs.com/YuanShuai/p/Joe.html
Copyright © 2011-2022 走看看