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>
    
  • 相关阅读:
    tomcat加载项目原理解惑
    英语口语大全
    ubuntu中wubi正在下载ubuntu11.04desktopi386.iso
    Strust2获得session和request
    字符串转成对象
    DevExpress控件使用
    DevExpress控件之GridControl控件(控件篇)
    ASP.NET AJAX + JSON 实现对象调用
    WinForm窗体之间交互的一些方法[转]
    barmanager设置
  • 原文地址:https://www.cnblogs.com/yangyp/p/3113772.html
Copyright © 2011-2022 走看看