I create a service for adding IOT devices to the list. When sending data I get an error:
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource
I tried like this:
xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = cfunc;
xmlhttp.open("POST", url, true);
xmlhttp.setRequestHeader("Authorization", "Basic " + auth);
xmlhttp.setRequestHeader('Content-type', 'application/json');
xmlhttp.setRequestHeader('Access-Control-Allow-Origin', '*');
xmlhttp.setRequestHeader('Access-Control-Allow-Methods', 'POST, GET, DELETE, PUT');
xmlhttp.setRequestHeader('Access-Control-Allow-Headers', 'x-requested-with,Content-Type');
xmlhttp.send(JSON.stringify(jsonString));
but the error was repeating so I tried to do this, with the same error:
$.ajax({
type: 'POST',
url: 'https://pmhhdo.internetofthings.ibmcloud.com/api/v0002/bulk/devices/add',
headers: {
'Authorization': 'Basic ' + auth,
'Content-Type':'application/json',
'Access-Control-Allow-Origin': 'https://pmhhdo.internetofthings.ibmcloud.com',
'Access-Control-Allow-Methods': 'GET, POST, PATCH, PUT, DELETE, OPTIONS',
'Access-Control-Allow-Headers': 'Origin, Content-Type, X-Auth-Token'
},
withCredentials: true,
crossDomain: true,
data: jsonString,
dataType: 'json',
success : function(data) {
},
});
Any ideas what I need to do?