zoukankan      html  css  js  c++  java
  • Js/Ajax中发送HttpPost请求调用WebService

    1) WebService中的方法

        [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 WebServiceDemo : System.Web.Services.WebService

        {

     

            [WebMethod]

            public string HelloWorld(string name)

            {

                return "Hello World,"+name;

            }

    }

    2) WebForm页面中的js代码

    <script src="Scripts/jquery-1.7.1.js"></script>

        <script>

            $(function () {

                $.ajax(

                    {

                        type: "post",

                        url: "http://localhost:10974/WebServiceDemo.asmx/HelloWorld",

                        data: "name=king",

                        success: function (msg) {

                            var text = msg.childNodes[0].textContent;

                            alert(text);

                        }

                    }

                    );

            });

        </script>

    3)执行结果

  • 相关阅读:
    uva1610 Party Games
    uva1442 Cav
    uva1609 Foul Play
    uva1608 Non-boring sequences
    uva12174 滑动窗口+预处理
    uva 1451 数形结合
    light oj 1336 sigma function
    找常用词(字符串处理)问题
    指定排序问题
    完数问题
  • 原文地址:https://www.cnblogs.com/Extreme/p/3463759.html
Copyright © 2011-2022 走看看