【发布时间】:2018-10-03 12:52:34
【问题描述】:
我从 Dynamics CRM 365 中的 javascript 网络资源调用了 google API。
var xhr = new XMLHttpRequest();
xhr.open("GET", 'https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input={' + searchString + '}&types=address&language=en&crossDomain=true&key=[ourKey]', true);
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.setRequestHeader('Access-Control-Allow-Methods', 'GET,POST');
xhr.onload = function () {
var response = JSON.parse(xhr.responseText);
//do something with the response here
};
xhr.send();
我在 IE 的开发工具中收到以下消息和错误:
*SEC7118:https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input={55 lllll}&types=address&language=en&crossDomain=true&key=[ourKey] 的 XMLHttpRequest 需要跨域资源共享 (CORS)。 文件:ClientApiWrapper.aspx
SEC7119:https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input={55 lllll}&types=address&language=en&crossDomain=true&key=[ourKey] 的 XMLHttpRequest 需要 CORS 预检。 文件:ClientApiWrapper.aspx
SEC7120:在 Access-Control-Allow-Origin 标头中找不到来源 http://[ourURL]。 文件:ClientApiWrapper.aspx
SCRIPT7002:XMLHttpRequest:网络错误 0x80070005,访问被拒绝。 文件:ClientApiWrapper.aspx*
浏览了 CORS 相关材料和指南,我相信我做的一切都是正确的。
我也试过这个,虽然我预计这里会出现 CORS 问题:
jQuery.post('https://maps.googleapis.com/maps/api/place/queryautocomplete/json?input={' + searchString + '}&types=address&language=' + langCode + '&key=[ourKey]', 函数(地址){
试试 {
//Do something with returned addresses here...
}
catch (e) {
alert("AutoComplete ErrorInt: " + e.message);
}
});
我确定这是与 Dynamics CRM 相关的问题,其中动态在它自己的沙盒之外不能很好地发挥作用。
任何人都可以在 Dynamics CRM 领域内提出修复建议吗?
谢谢
【问题讨论】:
-
您似乎需要配置您的 Dynamics CRM 以将其
Origin: http://[ourURL]标头与请求一起发送。如果无法配置,可以尝试自己设置:xhr.setRequestHeader('Origin', 'http://[ourURL]');. -
是的,试过了。完整的 URL 和通配符……仍然没有。我确信 CRM 会抑制标头,即使它们已设置。有趣的是,向 MS Support 提出了一张票,他们说这是一个谷歌问题。但是这在 CRM 之外是有效的,所以,不。还有其他建议吗?有人吗?
-
在添加带有完整 URL 的标头后,我得到:SEC7120: Origin http://[ourUrl] not found in Access-Control-Allow-Origin 标头。文件:ClientApiWrapper.aspx
标签: cors cross-domain dynamics-crm