SIGN UP MEMBER LOGIN:    
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
share 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
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Team Foundation Server Hosting
Become a Sponsor