本文介绍了如何在Ajax Url中传递参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发了一个成功运行的服务。以下是我的服务代码:



I have developed a service which is running successfully. Following is my service code:

namespace WcfService1
{
    [ServiceContract]
    public interface IService1
    {
        [OperationContract]
        [WebInvoke(Method="GET", ResponseFormat = WebMessageFormat.Json, BodyStyle=WebMessageBodyStyle.Wrapped, UriTemplate="/display/{a}/{b}")]
        string Display(string a, string b);
    }
}





我的服务:





My Service:

namespace WcfService1
{
   public class Service1 : IService1
    {
        public string Display(string a, string b)
        {
            int ab = Convert.ToInt32(a);
            int bc = Convert.ToInt32(b);
            int cb = ab + bc;
            return cb.ToString();
        }
    }
}





如何在ajax网址的帮助下调用此方法?我已经尝试了以下代码,但它无法正常工作。





How do i call this with the help of ajax url? I have tried out the following code but it is not working.

<script type="text/javascript">
        $(document).ready(function () {
            $('#BtnRegister').click(function () {
                debugger;

                var No1 = document.getElementById('TxtFirstNumber').value;
                var No2 = document.getElementById('TxtSecondNumber').value;

                $.ajax({
                    cache: false,
                    type: "GET",
                    async: false,
                    url: "http://localhost:22727/Service1.svc/Display",
                    data: 'a=' +No1+'&b='+No2,
                    contentType: "application/json; charset=ytf-8",
                    dataType: "json",
                    processData: true,
                    success: function (result) {
                        alert("data");
                    },
                    error: function (xhr, textStatus, errorThrown) { alert(textStatus + ':' + errorThrown); }
                });
            });
        });
    </script>

推荐答案




这篇关于如何在Ajax Url中传递参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 21:21
查看更多