1
Answer

Ajax call to a web method does not give response

Pranjal Vatsa

Pranjal Vatsa

11y
1.7k
1
Hi,

I am calling a javascript method from the click of a link:

<a href="#" onclick="get_project_details('<%# Eval("projectIdentifier") %>');"><%# Eval("projectIdentifier") %></a>

The javascript:

  <script type="text/javascript">
        function get_project_details(project_identifier) {
            $.ajax({
                type: "POST",
                url: "View.asmx/HelloWorld",
                data: "{}",
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                sucess: OnSuccess,
                failure: OnError
            });     
        }

        function OnSuccess(data, status) {
            alert(data.d);
        }

        function OnError(request, status, error) {
            alert(request.statusText);
        }
    </script>

As you can see, the Ajax call is to a web method HelloWorld() which is inside an asmx page:

  [WebMethod]
        public string HelloWorld()
        {
            return "Hello World";
          
        }
 
I do not get a response from the web method. When I try to debug the method by putting a break point, I see that the method is being 'hit'.

But the problem is that the response does not go back to the javascript function. I dont even get an error (OnError() does not give a result).

I tried inspecting the 'onclick' element from the browser and no help from there as well.

Am I missing some settings somewhere. Any kind of help is greatly appreciated.

Regards,
Pranjal

Answers (1)