How to call ASP.Net web method using JQuery AJAX

In normal ASP.NET web forms, if you want to send any data to server your web page will be refreshed i.e. will do a postback.
In some case, if you want to send data to the server without using any post back then in this case you have to use a web method at server side and that will be called from JQuery side.

How to implement ASP.Net web method using JQuery AJAX?

HTML Page:

<html xmlns=””>
    <script src=”js/jquery.min.js”></script>
        function SubmitData() {
            var name = ‘Ram’;
            var gender = ‘Male’;
            var age = ’30’;           
                type: “POST”,
                url: “ajaxcall.aspx/SaveData”,
                data: ‘{“name”:”‘ + name + ‘”, “gender”:”‘ + gender + ‘”, “age”:”‘ + age + ‘”}’,
                contentType: “application/json; charset=utf-8”,
                dataType: “json”,
                beforeSend: function () {
                success: function (data) {
                error: function (msg) {
                    msg = “There is an error”;
    <div id=”loader” style=”displaynone;“>
        <img src=”ajax-loader.gif” />
    <a href=”#” onclick=”SubmitData();”>Submit</a>

WebMethod written in aspx.cs page


    public static string SaveData(string name, string gender, string age)

            return “OK”;
        catch (Exception ex)
            return ex.Message;

Leave a Comment