0
[WebMethod]
public static string simple()
{
    Home h = new Home();
    h.logout();

    return "dfdsf";
}
public void logout()
{
    Response.Redirect(Config.Value("logout"));
}

client side code

$('#logout').on('click', function () {
    console.log("dfsnhkjdfsj");
    $.ajax({
        type:"GET",
        url: "Home.aspx/simple"
        }).done(function () {
        console.log("dfsds");
    });

});

http://localhost:14605/Home.aspx/simple 404 (Not Found) it is showing that method is not found please help to clear

2 Answers 2

1

Try to use without .aspx. Home is the name of your Controller and simple the name from the methode in your contoller.

$('#logout').on('click', function () {
    console.log("Clicked");
    $.ajax({
        type:"GET",
        url: "Home/simple"
        }).done(function () {
        console.log("Done");
    });

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

3 Comments

Are there the same error when you call localhost:14605/Home/simple in your browser ? do you have a firewal who can block?
bt i am able to call other api's bt this is first time i am working with web method which is not working
what happen when you call it in browser ? same error (page not found)?
1

If your server side method is in your code behind, then this should work

JS

$('#logout').on('click', function () {
    console.log("Clicked");
    PageMethods.simple(yourParameterIfAny, onSucess, onError);
        function onSucess(result) {
            /*OK*/
        }
        function onError(result) { /*Error*/ }
});

and your script manager must has its property EnablePageMethods to true

            <asp:ScriptManager ID="ScriptManager1" runat="server" EnablePageMethods="true">
            </asp:ScriptManager>

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.