2

I'm trying to call a webmethod inside a aspx page but only the page load event loads.

The webmethod:

<WebMethod()> _
Public Shared Function Test() As String
    Return "hello"
End Function

The ajax call:

$.ajax({
    type: "POST",
    url: "../Custom/Policy.aspx/Test",
    dataType: "text",
    success: function (data) { alert(data);},
    error: function (request, status, error) {
        console.log(request.responseText);
    }
});

The funny thing is I managed to make it work in the past and even looked at the code but still I can't make it work and now I gave up....

Any assistance will be appreciated.

Thanks in advance.

9
  • Look at the console to see if there are errors. This looks fine to me. Where is the ajax function called exactly? Commented Jan 27, 2013 at 14:52
  • from chrome\firefox console while i'm in a page in my web-app, trying to activate the webmethod Commented Jan 27, 2013 at 15:00
  • so what can you see in the console? Is the response text printed to the console? What status code do you see for the request Commented Jan 27, 2013 at 15:06
  • 200 - OK And I get in return the whole aspx page after page_load function finishes. Commented Jan 27, 2013 at 15:11
  • 1
    add these arguments to your ajax call: contentType: "application/json; charset=utf-8", dataType: "json", AFAIK the return type for calling a WebMethod MUST be "json". Commented Jan 27, 2013 at 15:14

1 Answer 1

2

The problem was I pass to data a native JSON object. Once I passed this object as String it started to work!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.