【发布时间】:2016-07-29 23:27:14
【问题描述】:
我目前正在尝试从 Marketo 的 API 检索和发送数据。问题是:我的网络平台是 Salesforce Community。如果我正确理解了这个网络工具,除了纯 javascript,我不能使用任何其他东西。
我已经构建了一个这样的 CORS 请求:
function createCORSRequest(method, url) {
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr) {
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined") {
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
function makeCorsRequest() {
var url = document.getElementById('url').value;
var xhr = createCORSRequest('GET', url);
if (!xhr) {
alert('CORS not supported');
return;
}
xhr.onload = function() {
var text = xhr.responseText;
alert('Response from CORS request to ' + url + 'is : ' + text);
};
xhr.onerror = function() {
alert('Woops, there was an error making the request.');
};
xhr.send();
}
在http://www.html5rocks.com/en/tutorials/cors/ 的帮助下,但由于此错误再次出现,服务器似乎不接受请求:
“请求的资源上不存在'Access-Control-Allow-Origin'标头。因此不允许访问源'http://testurl...'。”
有人知道 Marketo 的 API 是否接受 CORS 请求吗?或者也许有一个想法可以帮助我解决这个问题?非常感谢。
【问题讨论】:
标签: javascript api rest marketo salesforce-communities