ajaxpro.2.dll 简单应用

本文介绍了一种简化AJAX编程的方法,通过使用AjaxPro库,仅需几个步骤即可实现服务器时间和客户端之间的交互。具体包括添加AjaxPro.2.dll引用、配置web.config文件、编写服务器端代码以及客户端JavaScript回调函数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.添加 ajaxpro.2.dll 引用

2.web.config
<system.web>

    
<httpHandlers>
      
<add verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
    
</httpHandlers>
</system.web>

3.服务器端代码
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Ajax : System.Web.UI.Page
ExpandedBlockStart.gifContractedBlock.gif
{
    
protected void Page_Load(object sender, EventArgs e)
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        AjaxPro.Utility.RegisterTypeForAjax(
typeof(Ajax));
    }


    [AjaxPro.AjaxMethod]
    
public string GetServerTimeString()
ExpandedSubBlockStart.gifContractedSubBlock.gif    
{
        System.Threading.Thread.Sleep(
2000);
        
return DateTime.Now.ToString();
    }

}

4.客户端代码

ExpandedBlockStart.gifContractedBlock.gif<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Ajax.aspx.cs" Inherits="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 runat="server">
    
<title>ajaxpro.2.dll 简单应用</title>
ExpandedBlockStart.gifContractedBlock.gif    
<script language="javascript" type="text/javascript">
       
function ajax_callback(response)
ExpandedSubBlockStart.gifContractedSubBlock.gif       
{             
             document.getElementById(
"div1").innerHTML = response.value;
       }

       
function getServerTime()
ExpandedSubBlockStart.gifContractedSubBlock.gif       
{
          document.getElementById(
"div1").innerHTML = "请稍后,正在获取服务器时间..";
          Ajax.GetServerTimeString(ajax_callback);
          
       }

       
    
</script>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
    
    
<div id="div1">点击按钮获取服务器端时间</div>

    
<input type="button" value=" click " onclick="javascript:getServerTime();" />
    
    
</div>
    
</form>
</body>
</html>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值