使用 HTML Web 资源加载 Dynamics CRM 表单时,我从 Chrome 浏览器控制台收到以下错误。
https://xxxx.api.crm6.dynamics.com/api/data/v8.2/<自定义实体>。请求的资源上不存在“Access-Control-Allow-Origin”标头。因此,不允许访问来源“https://.crm6.dynamics.com”。响应具有 HTTP 状态代码 401。
<script type="text/javascript">
var clientUrl = "https://xxxx.api.crm6.dynamics.com/api/data/v8.2/"
function GetAccounts() {
var url = clientUrl + "accounts"
$.ajax({
method: "GET",
url: url,
async: false,
beforeSend: getAccountsBeforeSendCallback,
fail: getAccountsFailCallback,
done: getSavingGoalsDoneCallback,
success: getAccountsSuccessCallback
});
}
function getAccountsBeforeSendCallback(jqXHR, settings) {
debugger
jqXHR.setRequestHeader("OData-MaxVersion", "4.0");
jqXHR.setRequestHeader("OData-Version", "4.0");
jqXHR.setRequestHeader("Accept", "application/json");
jqXHR.setRequestHeader("Content-Type", "application/json; charset=utf-8");
}
</script>