【发布时间】:2013-11-20 16:37:16
【问题描述】:
我希望有人能解释为什么我在尝试从 JQuery ajax 方法调用时可能会在我的 ASP.Net VB.Net WebMethod 上收到 405 错误。
服务器实现:
<WebMethod()> _
Public Shared Function DoSomething(id As String) As String
Dim vm As HssViewModel = New HssViewModel()
Dim jResult As String = JsonConvert.SerializeObject(vm)
Return jResult
End Function
JavaScript 实现:
$.ajax({
type: "POST",
url: "mypage.aspx/DoSomething",
contentType: "application/json; charset-utf-8",
data: { 'id': 'ABC12345' },
dataType: "json",
cache: true,
succes: function (data) {
context = data;
console.log(data);
},
error: function (err) {
console.log("JQUERY ERROR RESPONSE: " + err.message);
}
});
我一直收到以下错误消息:
POST http://localhost/mypage.aspx/DoSomething 405 (Method Not Allowed)
我也尝试设置脚本方法标签以允许 GET 请求,但随后收到 404
<ScriptMethod(UseHttpGet:=True, ResponseFormat:=ResponseFormat.Json)> _
【问题讨论】:
标签: jquery asp.net vb.net webmethod