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

    }

  • 相关阅读:
    js数据结构Map -----字典
    配置一个高效快速的Git环境
    Ubuntu下dlib库编译安装
    空间域二阶统计纹理
    Markdown语法
    Notepad++中NppExec的使用之一:基本用法
    斯坦福大学机器学习笔记及代码(一)
    安家落户
    Android App开发常用专题开源代码
    Android基础-EditText键盘的显示与隐藏
  • 原文地址:https://www.cnblogs.com/YuanShuai/p/Joe.html
Copyright © 2011-2022 走看看