banner



How To Call Asp.net Restful Web Service Using Jquery

In this article, I am going to share how to call ASP.Internet Web Service method using jQuery AJAX.

Step iCreate an empty ASP.NET Spider web Awarding.

ASP.NET Web Service

Step 2Correct-click on the Project to add a service to your awarding (Add>New Item) and click on "New Detail" pick as shown in the below moving-picture show.

ASP.NET Web Service

Step 3

Select Web Service item (ASMX) and give the proper noun as y'all want. I accept left the default name and clicked on Add option. In my case, the name of the service is WebService1.asmx.

ASP.NET Web Service

Step 4Once you have added the service, you will become the following code.

ASP.NET Web Service

Step 5Permit united states focus on the comment. The given annotate is "To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the post-obit line". It means - you will accept to uncomment the below (// [System.Web.Script.Services.ScriptService]) code to be called from jQuery AJAX.

Step half dozenI have changed "HelloWorld" function parameter and passed one parameter named as myUserName and data blazon as a string. The role is returning "HelloWorld" plus input parameter.

ASP.NET Web Service

Step 7Now, it is fourth dimension to write jQuery AJAX code to call "HelloWorld" Service Method.

In club to write the code, you will take to add one webpage where you tin can write jQuery AJAX code. I take added one webpage to my awarding as you can see in the beneath image.

ASP.NET Web Service

Step 8Now, add jQuery script to the .aspx page(Script is given below) equally you tin can see in the given figure.

  1. <script src= "https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.two.1.min.js" ></script>

ASP.NET Web Service

Step nineWrite the following code inside the caput section of .aspx page  to call HelloWorld Method of WebService.

  1. <script type= "text/javascript" >
  2.     $(document).ready(function () {
  3.         $.ajax({
  4.             type:"Post" ,
  5.             url:"WebService1.asmx/HelloWorld" ,
  6.             information:"{'myUserName':'MyUserNameIsRaj'}" ,
  7.             contentType:"application/json" ,
  8.             datatype:"json" ,
  9.             success:function (responseFromServer) {
  10.                 warning(responseFromServer.d)
  11.             }
  12.         });
  13.     });
  14. </script>

Footstep 10

Now, see the final output.

ASP.NET Web Service

RemarksYou tin download this working awarding from the beneath link.

Source: https://www.c-sharpcorner.com/blogs/how-to-call-asp-net-web-service-using-jquery-ajax

Posted by: basssignitere.blogspot.com

0 Response to "How To Call Asp.net Restful Web Service Using Jquery"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel