zoukankan      html  css  js  c++  java
  • AjaxPro的使用

    AJAX 指异步JavaScript及 XML(Asynchronous JavaScript And XML),可以实现异步编程、局部刷新,节省客户端和服务器之间来回交互的数据量,本文主要介绍下.net中的Ajax框架AjaxPro的使用。

    1、先下载AjaxPro.2.dll,在项目中添加引用。

    2、在Web.Config中HttpHandler中添加如下配置:

    		<httpHandlers>
    			
    			<add verb="GET,POST" path="ajaxpro/*.ashx" type="AjaxPro.AjaxHandlerFactory,AjaxPro.2"/>
    		</httpHandlers>
    

     

    3、新建一个Ajax方法集中处理的类文件:

    namespace Demo.Common
    {
        [AjaxPro.AjaxNamespace("MyAjaxTest")]
        public class Common
        {
            [AjaxPro.AjaxMethod]
            public string GetString(string name)
            {
                return "Hello," + name;
            }
        }
    }
    

     4、新建一个Default.aspx页面,在页面Page_Load中注册Ajax方法:

        public partial class _Default : System.Web.UI.Page
        {
            protected void Page_Load(object sender, EventArgs e)
            {
                //Page_Load中注册AJAX可调用的类的名称
                AjaxPro.Utility.RegisterTypeForAjax(typeof(Common.Common));
            }
        }
    

     前端页面使用此Ajax方法的实例:

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
        <title>无标题页</title>
        <script type="text/javascript">
           function testAjax(){
              var txtName=document.getElementById("txtName").value;
              MyAjaxTest.GetString(txtName,alertMsg);
           }
           function alertMsg(res){
              alert(res.value);
           }
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <input type="text" id="txtName" />
        <input type="button" value="test" onclick="testAjax()" /> 
        </div>
        </form>
    </body>
    </html>
    
  • 相关阅读:
    shell基础优化脚本
    shell的常用脚本一
    Office/Visio/Project 2019 专业版iso
    vs2017 不能加载.vdproj
    CA机构及SSL证书
    singleWsdl和wsdl区别,Axis2和CXF对比
    在Window Server 2016中使用Web Deploy方式发布.NET Web应用
    NPOI导出excel
    audio隐藏下载按钮
    网站崩溃,如果提高网站并发能力
  • 原文地址:https://www.cnblogs.com/yangyp/p/3113772.html
Copyright © 2011-2022 走看看