我正在尝试通过AJAX POST调用来调用Web API函数,但始终收到405错误。 我一直在寻找,但一直在寻找说启用CORS的解决方案,但我没有这样做。 现在,我只是试图以html显示数据。 用户输入订单号,然后填写Web API函数的参数。 谁能告诉我怎么了?
我的Web API函数:
Public Function GetOrderContents(ByVal ordNbr As String) As SPFolderOver
Dim retValue As ReturnVal
retValue = GetOrderInformation(ordNbr)
Dim sp = New Sharepoint()
Dim t = sp.GetOrderContent(retValue.Year, retValue.SONumber)
Dim contentFolder = New SPFolderOver()
contentFolder = SPFolderOver.LoadFolder(t)
contentFolder.FolderName = t.FullPath
Return contentFolder
End Function
我的AJAX电话:
function GetOrder() {
var order = document.getElementById("orderNbr").value;
$.ajax({
cache: false,
type: "POST",
url: "http://localhost:54754/orders/{ordNbr}/contents",
data: { 'ordNbr': order },
success: function (data) {
$("#orderContents").html(data);
}
});
};
在我的global.asax中
Protected Sub Application_BeginRequest(ByVal sender As Object, ByVal e As EventArgs)
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Origin", "*")
If (HttpContext.Current.Request.HttpMethod = "OPTIONS") Then
HttpContext.Current.Response.AddHeader("Cache-Control", "no-cache")
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE")
HttpContext.Current.Response.AddHeader("Access-Control-Allow-Headers", "Content-Type, Accept")
HttpContext.Current.Response.AddHeader("Access-Control-Max-Age", "1728000")
HttpContext.Current.Response.End()
End If
End Sub
在我的Web.config中