zoukankan      html  css  js  c++  java
  • An example on how to use jQuery and Ajax.NET Professional together

    Get Started with the AjaxPro code

    Ajax.NET Professional (AjaxPro) is a Ajax Framework for the Microsoft .NET Framework which you can use with any .NET language like C#, VB.NET, J# to create JavaScript proxies to invoke any .NET method from the client-side. Download the AjaxPro.2.dll (for .NET 2.0) from http://www.ajaxpro.info/, add the reference and setup the web.config:

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

    Next we need to write our .NET method that will return the data we will ask for. A simple static method can be used with nearly any .NET data type, but I recommend to use only structs/classes with JavaScript similar data types for the properties.

     namespace MyNamespace
     {
       public class MyClass
       {
         [AjaxPro.AjaxMethod]
         public static string HelloWorld(string s)
         {
           return "Hello " + s;
         }
       }
     }
    

    The Ajax endpoint

    To get the name of the Ajax request endpoint you must use the namespace, classname and the assembly name like below:

     string path = "/ajaxpro/MyNamespace.MyClass,";
     path += typeof (MyClass).Assembly.FullName.Split(',')[0];
     path += ".ashx";
    

    Write the above string to a JavaScript variable using RegisterHiddenField or any other way.

    Run the AjaxPro request

    The next step would be to use jQuery to invoke the AjaxPro request. I used a very simple example to show what you need.

     $.ajax({
       type: "POST",
       url: MyAjaxPath,     // this is the path from above
       data: '{"s":"Hans"}',
       beforeSend: function(xhr) {
         xhr.setRequestHeader("X-AjaxPro-Method", "HelloWorld");
       },
       success: function(s) {
         var o = null;
         eval("o = " + s + "*"+"/");
         alert(o);
       }
     });
    
  • 相关阅读:
    中文字体网页开发指南
    使用免费模板需要注意的几个问题
    bootstrap总结
    HTML5 新模块元素兼容问题
    Oracle EBS 系统仅存在英文的环境
    Oracle EBS INV 更新物料慢
    Oracle EBS 跳跳转标准销售订单程序转标准销售订单程序
    Oracle EBS 数据访问权限集
    Oracle 数据库执行慢SQL
    Oracle EBS AR 事务处理到期余额总计API
  • 原文地址:https://www.cnblogs.com/weekend001/p/1602170.html
Copyright © 2011-2022 走看看