vsrm.dev.azure.com 被 CORS 阻止
vsrm.dev.azure.com is blocked by CORS
我能够通过 $.ajax.get 调用访问 vsrm.dev.azure.com API
即 https://vsrm.dev.azure.com/microsoft/***/_apis/release/definitions/****
现在我开始收到 CORS 错误:
从源'http访问'https://vsrm.dev.azure.com/microsoft//_apis/release/definitions/'处的XMLHttpRequest: //localhost:8080' 已被 CORS 策略阻止:请求的资源上不存在 'Access-Control-Allow-Origin' header。
有什么解决办法吗?
ajax get
现在对我仍然有效,没有任何错误消息。由于您没有分享您的任何代码,这里我只提供您我的代码:
<script type="text/javascript">
$(document).ready(function () {
$("#click").on("click", function () {
$.ajax({
type: 'GET',
url: 'https://vsrm.dev.azure.com/{org}/{project name}/_apis/release/definitions/{id}?api-version=5.1',
cache: false,
dataType: 'json',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("" + ":" + "{PAT token}"));
},
}).done(function (data) {
alert(data);
}).error(function (e) {
var s = "error error error";
});
})
});
</script>
你可以试试我的,看看是否适合你。
更新:
我在脚本中覆盖了 org name
、project name
、release definition id
和 PAT token
,请将其替换为您的可用值。
我能够通过 $.ajax.get 调用访问 vsrm.dev.azure.com API 即 https://vsrm.dev.azure.com/microsoft/***/_apis/release/definitions/****
现在我开始收到 CORS 错误: 从源'http访问'https://vsrm.dev.azure.com/microsoft//_apis/release/definitions/'处的XMLHttpRequest: //localhost:8080' 已被 CORS 策略阻止:请求的资源上不存在 'Access-Control-Allow-Origin' header。
有什么解决办法吗?
ajax get
现在对我仍然有效,没有任何错误消息。由于您没有分享您的任何代码,这里我只提供您我的代码:
<script type="text/javascript">
$(document).ready(function () {
$("#click").on("click", function () {
$.ajax({
type: 'GET',
url: 'https://vsrm.dev.azure.com/{org}/{project name}/_apis/release/definitions/{id}?api-version=5.1',
cache: false,
dataType: 'json',
beforeSend: function (xhr) {
xhr.setRequestHeader("Authorization", "Basic " + btoa("" + ":" + "{PAT token}"));
},
}).done(function (data) {
alert(data);
}).error(function (e) {
var s = "error error error";
});
})
});
</script>
你可以试试我的,看看是否适合你。
更新:
我在脚本中覆盖了 org name
、project name
、release definition id
和 PAT token
,请将其替换为您的可用值。