2

So, I have done this before and made many many ajax calls For some reason this one doesn't work =(

What do I need to change to get this one to work?

Previously I had an internal server error 500, but after pasting some working code and renaming methods to shorter names finally it changed over to this error of Unknown web method.

Setup

I am using jQuery to make Ajax calls to WebMethods in my Codebehind for my ASP.NET page.

Here is my C# WebMethod

    [WebMethod(EnableSession = true)]
    [ScriptMethod]
    public string viewApps(string foo)
    {
        string x = "";

        //130 lines of useful code.

        x = "0";
        return x;
    }

Here is the Javascript/jQuery doing the ajax call. It is in side a with all my other ajax calls. The other ones work. This one does not. It triggered by an onclick event in the html.

        function viewApps() {

            var food = "hamburger";
            $.ajax(
            {
                //send selected makes
                type: "POST",
                url: "MassUpdater.aspx/viewApps",
                dataType: "json",
                data: "{foo:" + food + "}",
                contentType: "application/json; charset=utf-8",

                //process the response
                //and populate the list
                success: function (msg) {

                    //just for show
                },
                error: function (e) {

                    alert(JSON.stringify(e));
                    $('#result').innerHTML = "unavailable";
                }
            });

//to be uncommented later when functionality works.

            // populateBrakeConfigs();
            //  populateBedConfigs();
            //   populateBodyStyleConfigs();
            //   populateSpringConfigs();
            //   populateSteeringConfigs();
            //  populateWheeleBase();
            //   populateTransmission();
            //   populateDriveTypes();

            function populateBrakeConfigs() { }
            function populateBedConfigs() { }
            function populateBodyStyleConfigs() { }
            function populateSpringConfigs() { }
            function populateSteeringConfigs() { }
            function populateWheeleBase() { }
            function populateTransmission() { }
            function populateDriveTypes() { }

        }

The ajax error looks like this:

Ajax error

I am also willing to provide any additional code or information about my project upon request.

1 Answer 1

4

The answer unfortunately is that somehow the static keyword got left out of the WebMethod, therefore the ajax call cannot find it.

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.