@shivakrishna wrote:
I am trying to make rest call from my controller it’s showing error in console like
jquery.js:9566 OPTIONS https://url/api/ 401 (Unauthorized)
localhost/:1 XMLHttpRequest cannot load https://url/api/ . Response to preflight request doesn’t pass access control check: No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘http://localhost:4200’ is therefore not allowed access. The response had HTTP status code 401.
this is my code in controller
Ember.$.ajax( {
method : 'GET', url : 'myapiurl', headers: { "Authorization" : "Basic abcdef==" },
}).then((response) => {
console.log(“response”);
//console.log(JSON.stringify(response));
});
and i tried with these options also
contentType: “application/json; charset=utf-8”,
jsonp: false, jsonpCallback: "localJsonpCallback", cache:true,
when i use jsonp:false then i got error like unauthorised
and also i found in stack-overflow is
For ajax requests to work backend should serve the proper ‘Access-Control-Allow-Origin’ header in response. Otherwise your browser would not accept such responses and throw an error that you are seeing. It’s not Ember related in any way it’s just how browsers work.
Now to fix this issue you would have to add the proper client server name to your backend ‘Access-Control-Allow-Origin’ headers. I.e. if you are going to serve your Ember app from https://example.com that is what you need to add to ‘Access-Control-Allow-Origin’ header.
then i start ember with ember s --proxy url
still there is no success , and i want to know there is any other way to make rest call not from the controller ,i tried same code in route handler. please help me thank you
Posts: 1
Participants: 1