我正试图从我对.net核心应用程序的视图中对跨域API进行Ajax调用,如下所示 -
$.ajax({
type: "POST",
url: 'https://logistics.arcgis.com/arcgis/rest/services/World/VehicleRoutingProblem/GPServer/SolveVehicleRoutingProblem/submitJob?token=' + key + '&time_units=Minutes&default_date=1355212800000&f=json',
data: { "orders": orders, "routes": routes, "depots": depots },
dataType: "json",
contentType: 'application/json;charset=UTF-8',
//headers: {
// 'Access-Control-Allow-Origin': '*',
// 'Access-Control - Allow - Methods': 'HEAD, GET, POST, PUT, PATCH, DELETE',
// 'Access- Control - Allow - Headers': 'Content-Type, origin, authorization, accept, client-security-token',
// 'Access-Control-Allow-Credentials':'true'
//},
success: function (json) {
//
},
error: function (request, status, error) {
console.log(error);
}
});
但是回应正在给予 -
Response to preflight request doesn't pass access control check: No 'Access-
Control-Allow-Origin' header is present on the requested resource. Origin
'http://localhost:61759' is therefore not allowed access. The response had
HTTP status code 403.
经过分析,我发现应用程序正在设置一个名为XSRF-Token(Anti Frogery Token)的cookie,导致问题,
如果我在手动调试期间禁用cookie,则AJAX调用正常。
需要一个解决方法才能成功进行AJAX调用吗?