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);
       }
     });
    
  • 相关阅读:
    container宽度
    NO.14 两个div并排,左边为绝对宽度,右边为相对宽度
    CSS3旋转图片效果收集
    背景图片问题
    CSS动画
    前端比较有用的网址
    JS如何判断IE和火狐与Chrome浏览器
    JAVA多线程面试题目
    JAVA多线程之Semaphore
    阿里多线程笔试题
  • 原文地址:https://www.cnblogs.com/weekend001/p/1602170.html
Copyright © 2011-2022 走看看