I am getting this error in browser console when running my JavaScript and jQuery code. Does anyone have this error in past? Any help will be appreciated.
Error:
condition: without any datatype selected
ERROR1: Browser console error: Access to XMLHttpRequest at “https://apex/api” from origin “http://xyz.8888” has been blocked by CORS policy: Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource.
condition: With datatype set to ‘jsonp’
ERROR2: No browser console error but getting no response back. But get this under the chrome browser Network tab for the call to API: (failed) net::ERR_BLOCKED_BY_ORB
Updated my ajax call as follows:
Tried setting up datatype to ‘jsonp’
Tried setting headers with Access-Control-Allow-Origin to *
// Download the data
myConnector.getData = function(table, doneCallback) {
console.log("Inside Data download");
*****Works until here, but fail at this ajax call*********
$.ajax({
crossDomain: true,
headers: {'Access-Control-Allow-Origin': '*'},
dataType: 'jsonp', ====> IF YOU REMOVE DATATYPE IT GIVES ERROR 1 ABOVE WITH DATATYPE IT GIVES ERROR 2
url: 'https://apex/api',
success: function(resp){
var feat = resp.features,
tableData = [];
// Iterate over the JSON object
for (var i = 0, len = feat.length; i < len; i++) {
tableData.push({
"id": feat[i].id
});
}
table.appendRows(tableData);
doneCallback();
}
});
};
user19354065 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.