Discussions

Ask a Question
Back to all

Access Rest Api from Javascript - CORS exception

Hello, I'm starting to use the Rest Api, but from the begining I'm facing a problem with CORS.

Using javascript I'm able to get the token from https://mysite.com/imis/token

After that, I get the access_token for the subsequent calls, but it I do a simple call to https://mysite.com/imis/api/party/900111 I get this error in my browser Console

"Access to XMLHttpRequest at 'https://mysite.com/imis/api/party/900111' from origin 'http://localhost:4200' 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."

And this is the JavaScript code I'm trying to execute:

$.ajax("https://mysite.com/imis/api/party/900111",
{
type : "PUT",
contentType: "application/json",
data: JSON.stringify({ "$type": "Asi.Soa.Membership.DataContracts.PersonData, Asi.Soa.Membership.Contracts",

"PersonName": {

"$type": "Asi.Soa.Membership.DataContracts.PersonNameData, Asi.Soa.Membership.Contracts",

"FirstName": "Peter",

"LastName": "Carlton",

"NamePrefix": "Mr."

},

"PartyId": "900111"}),

dataType: "json",

crossDomain: true,

headers: {
"RequestVerificationToken": response.access_token,
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Headers": "x-requested-with"
},

success: function(data){
console.log(data);
}

})

Thank you!

Contact us
Copyright © Advanced Solutions International, All rights reserved.