ARTICLE

Difference Between Calling a Web Service using jQuery and AJAX

Posted by Shinuraj Articles | JQuery February 15, 2011
We see here difference between calling a web service using jQuery and ASP .NET AJAX.
Reader Level:

Here is the code for calling a web service using jQuery

<html>
<head id="Head1" runat="server">
<title>ASP.NET AJAX Web Services: Web Service Sample Page</title>
 <script type="text/javascript"  src="http://ajax.googleapis.com/ajax/libs/jQuery/1.2.6/jQuery.min.js">  
</script> 
  <script type="text/javascript">
      $(document).ready(function() {
         $("#btnTest").click(function(event) {
             $.ajax({
                 type: "POST",
                 url: "dummyWebsevice.asmx/HelloToYou",
                 data: "{'name': '" + $('#name').val() + "'}",
                 contentType: "application/json; charset=utf-8",
                 dataType: "json",
                 success: function(msg) {
                     AjaxSucceeded(msg);
                 },
                 error: AjaxFailed
             });
         });
     });
          function AjaxSucceeded(result) {
              alert(result.d);
          }
          function AjaxFailed(result) {
              alert(result.status + ' ' + result.statusText);
          } 
  </script> 
</head>
<body>
    <form id="form1" runat="server">
     <h1> Calling Web Services using  jQuery </h1>
     Enter your name:
        <input id="name" />
        <br />
        <input id="btnTest" value="Test WebService"
               type="button"  />
    </form>
</body>
</html>

Here is the code for calling a web service using ASP.NET Ajax:

<html>
<head id="Head1" runat="server">
<title>Calling Web Services using asp.net ajax</title>
  <script type="text/javascript">
      function OnClick() {
          var txtName = $get("name");
          dummyWebservice.HelloToYou(txtName.value, SayHello);
      }
      function SayHello(result) {
          alert(result);
      }
  </script> 
</head>
<body>
   <form id="form1" runat="server">
    <asp:ScriptManager ID="_scriptManager" runat="server">
      <Services>
        <asp:ServiceReference Path="dummyWebsevice.asmx" />
      </Services>
    </asp:ScriptManager>
    <h1>Calling Web Services using asp.net ajax </h1>
     Enter your name:
        <input id="name" />
        <br />
        <input id="btnTest" value="Test"
               type="button" onclick="OnClick();" />
    </form>
</body>
</html>

Login to add your contents and source code to this article
post comment
     

That's a good article. Very helpful. It looks like Microsoft finally stopped development of the ASP.Net Ajax library. So jQuery is probably the way to go in the future.

Posted by Andrew Fenster Apr 05, 2011
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Get Career Advice from Experts