How to Call C# Method/Function Using jQuery Ajax

I will use the jQuery.ajax() or $.ajax() method to call the C# method (WebMethod). The $.ajax() method does an asynchronous HTTP (Ajax) request. This method will take various parameters. So you will get the entire parameters list in a link: https://api.jquery.com/jQuery.ajax/

You need add the jQuery library to you project in order to run this jQuery Ajax call. You can download the jQuery library form this link: http://jquery.com/download/

Here is the jQuery Script.



Here is the C# function.





Output



Note

  1. Here I declared the C# method as WebMethod and it should be static.
  2. If this method is not static then you will get an error and the method will never be called.
  3. Download the code to test this $.ajax() functionality.

Up Next
    Ebook Download
    View all
    Learn
    View all