仅使用javascript调用Marketo API
我目前正在尝试从Marketo的API检索和发送数据。问题是:我的web平台是Salesforce社区。如果我正确理解这个web工具,我就不允许使用纯javascript以外的任何东西 我构建了一个CORS请求,如下所示:仅使用javascript调用Marketo API,javascript,api,rest,marketo,salesforce-communities,Javascript,Api,Rest,Marketo,Salesforce Communities,我目前正在尝试从Marketo的API检索和发送数据。问题是:我的web平台是Salesforce社区。如果我正确理解这个web工具,我就不允许使用纯javascript以外的任何东西 我构建了一个CORS请求,如下所示: function createCORSRequest(method, url) { var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { xhr.open(method, url, t
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();
}
在的帮助下,但服务器似乎不接受请求,因为此错误再次出现:
“请求的资源上不存在'Access Control Allow Origin'标头。因此不允许访问源'…。”
有人知道Marketo的API是否接受CORS请求吗?或者你有什么想法可以帮我解决这个问题?非常感谢。Marketo REST API将不允许CORS请求。在浏览器中的客户端上进行调用也是一种安全风险,因为您将公开您的访问令牌。根据您试图做的事情,可能会有其他选择,或者您可以设置一个简单的服务来代理您的请求