Pranjal Vatsa

Pranjal Vatsa

  • NA
  • 1
  • 3.5k

Ajax call to a web method does not give response

Aug 8 2013 7:49 AM
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)