1
我目前正在嘗試從Marketo的API中檢索和發送數據。問題是:我的Web平臺是Salesforce Community。如果我正確理解這個網絡工具,我不允許使用純JavaScript以外的任何東西。使用JavaScript調用Marketo API
我已經建立了這樣的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'標題出現在請求的資源上。Origin'http://testurl ...'因此不允許訪問。「
有沒有人知道Marketo的API是否接受CORS請求?或者也許有一個想法可以幫助我解決這個問題?非常感謝你。