首页 > Web开发 > 详细

js调用webservice(1)——ScriptManage

时间:2014-03-22 03:59:39      阅读:407      评论:0      收藏:0      [点我收藏+]
1
2
<span style="color: rgb(255, 0, 0);">//注意:该方法仅支持同网站目录调用(即相对路径,不支持网络路径),是为一种js调用C#函数的方法之一
</span>

 

前台代码:

<asp:ScriptManager ID="ScriptManager1" runat="server">
  <Services>
   <asp:ServiceReference Path="/WebService1.asmx" InlineScript="true" />
  </Services>
 </asp:ScriptManager>

<script type="text/javascript" language="javascript">
        function func1()
        {        
        WebApplication1.WebService1.HelloWorld(onSuccess,onFail,‘Span1‘);
        }

        function onSuccess(value,context)
        {
        document.getElementById(context).innerHTML=value;
        }
        function onFail(value)
        {
        alert(value);
        }
 </script>

 

后台代码:

 

using System.ComponentModel;

using System.Web.Services;

 

namespace WebApplication1

{

 

    [System.Web.Script.Services.ScriptService]

    public class WebService1 : System.Web.Services.WebService

    {

 

        [WebMethod]

        public string HelloWorld()

        {

            return "Hello World";

        }
    
    }

}

js调用webservice(1)——ScriptManage,布布扣,bubuko.com

js调用webservice(1)——ScriptManage

原文:http://www.cnblogs.com/liudayuan/p/3616406.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!