0

I am making JQuery Ajax call in asp.net, I am returning String with my WebMethod, But on success of ajax call I am getting complete HTML of page in result.I also used type: "get" but no luck, below is my code for ajax call

$.ajax({
    type: "POST",
    url: "MyPage.aspx/GetData", //url to point your webmethod          
    success: function (Result) {
        if (Result != "")
            alert( Result);
        },
    error: function () { alert('error'); }
});

[System.Web.Services.WebMethod()]
public string GetData()
{
    //getting value from Database and returning
}

I am calling this Ajax in MyPage.aspx

2
  • can you post the webmethod? Commented Aug 15, 2013 at 11:03
  • @Xikinho90 I have posted the method as well, GetData() Commented Aug 15, 2013 at 11:03

1 Answer 1

1

Try it like this. With the contentType: "application/json; charset=utf-8"

$.ajax({
    type: "POST",
    url: "MyPage.aspx/GetData", //url to point your webmethod          
    contentType: "application/json; charset=utf-8",
    success: function (Result) {
        if (Result != "")
            alert( Result);
        },
    error: function () { alert('error'); }
});
Sign up to request clarification or add additional context in comments.

1 Comment

Unknown web method GetData.<br>Parameter name: methodName

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.