i'm doing this request in ajax but i still have this following error about CORS: XMLHttpRequest cannot load https://cubber.zendesk.com/api/v2/organizations/37520251/users.json. Request header field Access-Control-Allow-Origin is not allowed by Access-Control-Allow-Headers in preflight response. Can you help me pls ( i have seen many topic and i still don't understand why it is not working
function afficheorga(a){
$.ajax({
url: "https://cubber.zendesk.com/api/v2/users/"+a+"/organizations.json",
type: 'GET',
dataType: 'json',
cors: true ,
contentType:'application/json',
secure: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa(""));
},
success: function (data){
console.log(data.organizations[0].name);
var organisation = data.organizations[0].name;
$("#company").text(organisation);
}
})
}
You could get around this by using jsonp
. Change dataType
to jsonp
so your GET
request should be as follows
function afficheorga(a){
$.ajax({
url: "https://cubber.zendesk.com/api/v2/users/"+a+"/organizations.json",
type: 'GET',
dataType: 'jsonp',
cors: true ,
contentType:'application/json',
secure: true,
headers: {
'Access-Control-Allow-Origin': '*',
},
beforeSend: function (xhr) {
xhr.setRequestHeader ("Authorization", "Basic " + btoa(""));
},
success: function (data){
console.log(data.organizations[0].name);
var organisation = data.organizations[0].name;
$("#company").text(organisation);
}
})
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With