zoukankan      html  css  js  c++  java
  • 关于使用Ajax 用js调用web服务

      一下为主要要素:
         1.必须添加程序集 System.Web.Extensions.Design.dll System.Web.Extensions.dll 引用
         2.配置文件必须添加
      <system.web> 
        <httpHandlers>
          <!--ajax的配置開始 -->
          <remove verb="*" path="*.asmx"/>
          <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" validate="false"/>
          <!--ajax的配置結束 -->
        </httpHandlers>
     <compilation debug="false">
          <assemblies>
            <add assembly="System.Web.Extensions, Version=1.0.61025.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
          </assemblies>
        </compilation>
      </system.web> 
      3. webservices类必须添加下列属性 命名空间为using System.Web.Script.Services;
    [ScriptMethod()]
    public class DataSorceFactory : System.Web.Services.WebService
    {
    }
      4.aspx页面的调用
        <script type="text/javascript">
            function Show() {
                DataSorceFactory .Test(onsuccess, onFailed, null);
            }
            ///成功調用的方法
            function onsuccess(result) {
                alert(result);
            }
            ///失败调用的方法
            function onFailed(result) {
                alert("错误信息"+result.get_message());
            }
        </script>

    cs方法
    [ScriptMethod()]
    public class DataSorceFactory : System.Web.Services.WebService
    {
        [WebMethod]
        public string Test()
        {
            return "歡迎你 啊戴爾!";
        }
    }
      5.aspx页面的form必须添加
     <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
            <Services>
                <asp:ServiceReference Path="~/DataSorceFactory .asmx" />
            </Services>
        </asp:ScriptManager>
    </form>
  • 相关阅读:
    slots属性(省内存,限制属性的定义)
    自定制格式化方式format
    改变对象的字符串显示__str__repr
    __getattribute__和item系列
    授权(类似)
    双下划线开头的attr方法
    动态导入模块
    反射
    python的单下划线和双下划线
    在子类中调用父类的方法
  • 原文地址:https://www.cnblogs.com/ruonanxiao/p/1565800.html
Copyright © 2011-2022 走看看