我正在开发一个内部Web应用程序.在IE10中,请求工作正常,但在Chrome中,所有AJAX请求(有很多)都是使用OPTIONS发送的,而不是我给出的任何定义的方法.从技术上讲,我的请求是"跨域".该站点在localhost:6120上提供,我正在向AJAX请求的服务是在57124. 这个关闭的jquery错误定义了问题,但不是真正的修复.
如何在ajax请求中使用正确的http方法?
编辑:
这是在每个页面的文档加载中:
jQuery.support.cors = true;
Run Code Online (Sandbox Code Playgroud)
每个AJAX都是类似的:
var url = 'http://localhost:57124/My/Rest/Call';
$.ajax({
url: url,
dataType: "json",
data: json,
async: true,
cache: false,
timeout: 30000,
headers: { "x-li-format": "json", "X-UserName": userName },
success: function (data) {
// my success stuff
},
error: function (request, status, error) {
// my error stuff
},
type: "POST"
});
Run Code Online (Sandbox Code Playgroud) 我在向其他域上的Web API发出PUT和DELETE CORS请求时遇到一些麻烦.
我已经通过http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api#create-webapi-project教程对API进行了编码.
GET和POST请求工作正常,但DELETE和PUT没有.我收到这条消息:
Failed to load resource: the server responded with a status of 405 (Method Not Allowed)
Failed to load resource: No 'Access-Control-Allow-Origin' header is present on the requested resource.
Run Code Online (Sandbox Code Playgroud)
当我在使用ASP.NET Web API的CORS支持PUT和DELETE时向WebConfig添加代码时,我只得到第一个错误.
有人可以帮我这个吗?