1

I have the following code in my aspx.cs file:

[System.Web.Services.WebMethod]
public static string PostPin() {
    return "Rahul";
}

And the following Javascript:

$.ajax({
type: "POST",
url: "/adfs/ls/RequestPinForm.aspx/PostPin",
contentType: "application/json; charset=utf-8",
success: function(data) {
    alert(data);
},
error : function(data , data2 , data3) {
    alert(data);
}
});

I'm using the alert's to see the returns of what is coming back, but I can never get it to return the string.

Any ideas guys?

13
  • When I alert the data, the data returned is the HTML for the page, is that normal? It's not JSON return but the HTML of the page itself. Commented Oct 6, 2015 at 9:04
  • 1
    Use the [ScriptMethod(ResponseFormat = ResponseFormat.Json)] attribute to see if it returns a JSON format Commented Oct 6, 2015 at 9:05
  • ya this functionality is working perfect and return html as expected....all you need to do is serialize the output (here "rahul") and then return Commented Oct 6, 2015 at 9:06
  • Please add dataType="json" in your ajax call Commented Oct 6, 2015 at 9:10
  • 1
    See this stackoverflow.com/questions/27917255/… Commented Oct 6, 2015 at 9:15

0

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.