jQuery动态加载页面和请求所返回的数据

来源:互联网 发布:淘宝刷访客 编辑:程序博客网 时间:2024/06/11 06:58

Default.aspx页面

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>无标题页</title>
    <script src="jquery-1.3.2.mini.js" type="text/javascript"></script>
    <script type="text/javascript" language="javascript">
        function loadData()
        {
            //加载a.html到层
            $("#divData").load("a.html");
            //加载从data.ashx返回的数据到层
            //$.get("data.ashx", function(data){$("#divData").html(data);});
            //alert返回的数据
            //$.get("data.ashx", function(data){alert("Data Loaded: " + data);});

        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <a href="javascript:void(0);" onclick="loadData();">请求加载</a>
    <span id="divData"></span>
    </div>
    </form>
</body>
</html>

 

data.ashx

<%@ WebHandler Language="C#" Class="data" %>

using System;
using System.Web;

public class data : IHttpHandler {
   
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "text/plain";
        context.Response.Write("Hello World");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}

原创粉丝点击