Q:

How to return a ajax response in c#?

I am new to AJAX and C#, So i am trying how to work them together. I am building a web application and I am invoking a method from c# in my ajax function and if everything works fine then I want to receive the success message back to my c# class. How can I do that?
This is my ajax method
<script type="text/javascript">

 Hello();
    function Hello() {
        $.ajax({
            type: "POST",
            url: "Dtata.aspx/Hello",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (result) {
                response(result.d);
            },
            error: function (result) {
                alert('There is a problem processing your request');
            }
        });
    }

</script>

  //Basically I want to know the success/failure value from the Ajax call and print it back to my console.

   protected void Page_Load(object sender, EventArgs e)
    {

    }

    [WebMethod]
    public static string Hello(string name)
    {
        return name;
    }

A:

have you tried to pass also the data in your ajax call? (string name) .. cause your back end service (webMethod) have it in its method param...something like:
 <script type="text/javascript">

        Hello();
            function Hello() {
                $.ajax({
                    type: "POST",
                    url: "Dtata.aspx/Hello",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                    data:{name:'hello'},
                    success: function (result) {
                        response(result.d);
                        Counter() //<-- CALL OTHER AJAX METHOD TO INCREASE COUNTER ON BACK END
                    },
                    error: function (result) {
                        alert('There is a problem processing your request');
                    }
                });
            }

 function Counter() {
                $.ajax({
                    type: "POST",
                    url: "Dtata.aspx/Counter",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",

                    success: function (result) {
                        console.log(result.d);
                    },
                    error: function (result) {
                        alert('There is a problem processing your request');
                    }
                });
            }

        </script>

          //Basically I want to know the success/failure value from the Ajax call and print it back to my console.
         private int _counter;
           protected void Page_Load(object sender, EventArgs e)
            {

            }

            [WebMethod]
            public static string Hello(string name)
            {
                return name;
            }

             [WebMethod]
                public static int Counter()
                {
                    this._counter = this._counter +1;
                    return this._counter
                }

