Sunday, 2 February 2014

Call Wcf Rest services using jquery Ajax

    <section class="featured">

        <div class="content-wrapper">
            <hgroup class="title">
                <h1>@ViewBag.Title.</h1>
                <h2>@ViewBag.Message</h2>
            </hgroup>
            <p>
                To learn more about ASP.NET MVC visit
                <a href="http://asp.net/mvc" title="ASP.NET MVC Website">http://asp.net/mvc</a>.
                The page features <mark>videos, tutorials, and samples</mark> to help you get the most                     from ASP.NET MVC.
                If you have any questions about ASP.NET MVC visit
                <a href="http://forums.asp.net/1146.aspx/1?MVC" title="ASP.NET MVC Forum">our forums</a>.
            </p>
        </div>
    </section>
    <input type="text" id="LoginId" />
    <input type="text" id="Name" />
    <input type="submit" id="submit" />
  

}
<h2>Here is my Ajax Call:</h2>
<script type="text/javascript">
    $(document).ready(function () {
        $("#submit").click(function () {
            var input = $("#LogInID").val();
            $.ajax({
                cache: false,
                type: "GET",
                async: false,
                url: "http://localhost:7045/Service1.svc/GetData/"+input+"",
               //data:JSON.stringify(input) ,
                dataType: "json",
                success: function (data) {
                    viewModel.DiplayEmp(data.DiplayEmp);
                    //var user = JSON.stringify(data);
                    //alert(user);
                },
                error: function (xhr) {
                    alert(xhr);
                }
            });
        });
      
    });
</script>

No comments:

Post a Comment