Jquery Webapi Call

Posted on  by admin
Back to: ASP.NET Web API Tutorials For Begineers and Professionals.

In this article, I am going to discuss how to Consuming Web API Service From jQuery. We are going to work with the same example that we created in our previous article where we discussedParameter Bindingin WEB API.

So please read our previous article before proceeding with this article. When we click on the “Get All Employees” button, then we need to retrieve all the employee’s information and then display this information in an unordered list as shown in the image below.

When we click on the “Clear” button then we need to clear the employees from the unordered list.

Modify the Employee Controller of our project as shown below where we create one action which will return the list of employees.

Then modify the WebApiConfig class which is present in the inside App_Start folder as shown below.

Here we are changing the URI pattern to allow action name as part of the URL.

Right-click on the project and then select Add => Html page as shown below. In the next pop up specify the name for the HTML page and then click on the Ok button as shown in the image below.

Once you created the page then copy and paste the following code in it.

Call Web API POST Method from jQuery