如何在纯html中从jquery调用Web服务方法

时间:2017-01-15 18:30:50

标签: javascript jquery html web-services

我想从带有jquery的html调用Web服务函数,但它返回如下错误:

Message":"Invalid web service call, missing value for parameter: \u0027to\u0027.","StackTrace":"   at System.Web.Script.Services.WebServiceMethodData.CallMethod(Object target, IDictionary`2 parameters)...

www.xxxxx.com/website/demo.html上的html网页和www.xxxxx.com/web/xx.asmx

上运行的网络服务

这是我的js:

 <script>
        function mail() {


            var email = 'xxxx';
            var nameSurname = 'xxxx';
            var phone = 'xxx';
            var siteName = 'asdf';
            var numberOfApartment = '3';
            var mission = 'asdf';

            $.ajax({
                type: "GET",
                url: 'http://www.xxxxx.com/web/xx.asmx/SendMail',
                data: JSON.stringify({ to: email, nameSurname: nameSurname, phone: phone, siteName: siteName, numberOfApartment: numberOfApartment, mission: mission }),
                dataType: "json",
                contentType: "application/json",
                success: function (result) {
                    alert("Successed");
                },
                error:
                    function (result) {
                        alert('error');

                    }
            });
        }
    </script>

这是我的网络服务功能:

    [WebMethod]
    [ScriptMethod(UseHttpGet = true)]
    public string SendMail(string to, string nameSurname, string phone, string siteName, string numberOfApartment, string mission)
    {

       return "";
    }

我的错误在哪里?

0 个答案:

没有答案