• js调用WebService出现webserive未定义错误!


    引自:http://www.cnblogs.com/zjmzone/archive/2011/09/14/2176496.html

    namespace lwfxxxpt
    {
        /// <summary>
        /// WebService 的摘要说明
        /// </summary>
        [WebService(Namespace = "http://tempuri.org/")]
        [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
        [System.ComponentModel.ToolboxItem(false)]
        // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
        [System.Web.Script.Services.ScriptService]
        public class WebService : System.Web.Services.WebService
        {
            [WebMethod]
            public string HelloWorld()
            {
                return "Hello World";
            }
        }
    }

    用Soap路径要注意

    <asp:ScriptManager ID="ScriptManager1" runat="server">
                <Services>
                    <asp:ServiceReference Path="~/WebService.asmx" />
                </Services>
            </asp:ScriptManager>

    这样就没问题了:

    function btnNew_onclick() {          
     lwfxxxpt.WebService.HelloWorld(onCreated); 
    }
    

     加上WebService命名空间。

    补充:

    需注意的

    第一:取消注释

    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    //[System.Web.Script.Services.ScriptService]
    
    改成
    
    // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消对下行的注释。
    [System.Web.Script.Services.ScriptService]
    

    第二:命名空间

    namespace lwfxxxpt{
         .........
    }

    调用的时候需与命名空间一致

    function GetAreaList() { 
                lwfxxxpt.WebService.GetAllAreas(orderId,searchSql,UpageIndex,countPerPage,orderType,AreaTables);           
            } 

    因为一直困扰着这个问题,现在也弄明白了是怎么一回事了。谢谢 ω?zone咕咯。

  • 相关阅读:
    SpringMVC-乱码问题
    SpringMVC-数据提交
    SpringMVC-结果跳转方式
    SpringMVC-Controller&RestFul
    SpringMVC-基础
    Spring-声明式事务
    Spring-整合MyBatis
    Spring-AOP
    android 入门-工序
    android 入门-android Studio 解决方案
  • 原文地址:https://www.cnblogs.com/biye/p/2666102.html
Copyright © 2020-2023  润新知