Why is this jquery ajax GET call to C # method not working?

I have a C # .NET MVC 5 project. I am trying to send a GET request from ajax to a controller method on the server. The problem is that although this jquery is being called, GET always returns 404. Here is the js:

 var theArguments = { "prefix": prefix, "level": level, "number": number };
 $.ajax({
            url: "GetMasteryObjective",
            type: "GET",
            data: theArguments,
            //data: JSON.stringify({ prefix: "prefix", level: "level", number: "number" }),
            //url: "/MasteryObjectiveAPI/GetMasteryObjective?prefix=" + prefix + "&level=" + level + "&number=" + number,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function () {
                console.log("Successfully queried the database to validate the given mastery objective.");
            },
            error: function () {
                console.log("There was an error with trying to validate the mastery objective with the database.");
            }
        });

As you can see, I tried several options for how variables are passed (commented out). This is a controller method that never hits.

[HttpGet]
//[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static MasteryObjective GetMasteryObjective(String prefix, String level, String number)
{
     //code here
}

Other methods in one controller cannot be sent. So maybe something I don’t understand about GET? I understand that it must be valid for sending variables with a GET request.

+4
source share
2 answers

. , . static .

+4

, .

, , .....

, ajax :

[], .

. ; , [AllowAnonymous], , .

0

All Articles