How do I Pass Parameter in Ajax Url?

Posted by Nimit Joshi on Stack Overflow See other posts from Stack Overflow or by Nimit Joshi
Published on 2014-06-12T09:21:08Z Indexed on 2014/06/12 9:24 UTC
Read the original article Hit count: 196

Filed under:

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

namespace WcfService1
public interface IService1
    [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();

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 () {

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

                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) {
                error: function (xhr, textStatus, errorThrown) { alert(textStatus + ':' + errorThrown); }

© Stack Overflow or respective owner

Related posts about jQuery

Related posts about AJAX