0

Aspx Page

 <script>
 $(document).ready(function () {
    $.ajax({
            type: "POST",
            url: "WebForm1.aspx/GetData",
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
                $("#Content").text(response.d);
            },
            failure: function (response) {
                alert(response.d);
            }
        });
    });
</script>
</head>
<body>
<form id="frm" method="post">
    <div id="Content">
    </div>
</form>
</body>
</html>

Code behind

public static string GetData()
{
    return "This string is from Code behind";
}

I want to get this function using ajax without using "WEBMETHOD". i.e. GetData() method, I want to show in my .aspx page without using web service.

1
  • You need webmethod attribute. Commented Sep 16, 2015 at 13:41

1 Answer 1

1

i'm not sure i get your question but maybe what you are looking for is simply the code you need in the onload event of the page:

    protected void Page_Load(object sender, EventArgs e)
    {
        Response.ContentType = "application/json";
        Response.Write("put a valid json string here");
    }
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.