【发布时间】:2015-02-13 19:27:10
【问题描述】:
我有一个 C# .NET MVC 5 项目。我正在尝试从 ajax 向服务器上的控制器方法提交 GET 请求。问题是,即使调用了这个 jquery,GET 总是返回 404。这是 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.");
}
});
如您所见,我尝试了几种提交变量的变体(已注释掉)。这是永远不会受到打击的控制器方法。
[HttpGet]
//[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public static MasteryObjective GetMasteryObjective(String prefix, String level, String number)
{
//code here
}
同一控制器中的其他方法被发布到没有问题。所以也许我对 GET 有什么不明白的地方?我了解使用 GET 请求提交变量应该是有效的。
【问题讨论】:
标签: c# jquery .net ajax http-get