利用AjaxPro2实现前后台数据交互

1、准备:下载AjaxPro.2.dll

2、应用:项目中引用AjaxPro.2.dll

3web.config中引用:

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

4、后台页面代码:

public partial class test2 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        { 
        
        }
        AjaxPro.Utility.RegisterTypeForAjax(typeof(test2));  --test2为页面类名
    }
    //根据传递过来的商品规格获取商品信息
    [AjaxPro.AjaxMethod]  --声明AjaxPro
    public string GetProductInfoByDetail(string guid,string detail)
    {
        string refs = "0";
        if (detail != "")
        {
            string price = "";
            string proNum = "";
            string sql = "select * from tb1 where guid='" + guid + "' and detail='" + detail + "'";
            DataTable dt = mallCtr.SqlTable(sql);
            if (dt.Rows.Count > 0)
            {
                price = dt.Rows[0]["price"].ToString();
                proNum = dt.Rows[0]["RepertoryCount"].ToString();
                refs = price + "$$$" + proNum;
            }
            else
            {
                refs = "1";
            }
        }
        return refs;
    }
}

5、前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test2.aspx.cs" Inherits="test2" %>
<!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</title>
    
    <script language="javascript" defer=true>
function GetProductNum()
{
   refs=test2.GetProductInfoByDetail(document.getElementById("<%=TextBox1.ClientID %>").value,document.getElementById("<%=TextBox2.ClientID %>").value).value; //获取后台返回值
   if (refs!="0")
   {   
       //alert(refs); 
       var val=refs.split('$$$');
       document.getElementById("<%=TextBox3.ClientID %>").value=val[0];   //给textbox赋值
       document.getElementById("Label2").innerHTML = val[1];  //给label赋值
   }
}
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="GetProductNum();"/>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    <asp:Label ID="Label2" runat="server" Text="aa"></asp:Label>
    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
    </div>
        
    </form>
</body>
</html>

以上方式只能部署在Windows Server 2003+ IIS 6.0上,如部署在Windows Server 2008 + IIS 7.0上,除上述步骤外,还需要另外设置,具体如下:

1、在<system.webServer><handlers>下增加节点
<add name="ajaxpro" verb="*" path="*.ashx"type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>

<!--程序部署在windows server 2008+IIS7.0,需要在此处声明AjaxPro2,才能正常使用-->
  <system.webServer>
    <handlers>
      <add name="ajaxpro" verb="*" path="*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
    </handlers>
  </system.webServer>

或:

2、把应用程序池改为“经典模式”


下载地址: 利用AjaxPro2实现前后台数据交互实例下载

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值