I have design adapter in ember js which send requests to backend to get the data but getting a error "XMLHttpRequest cannot load https://example.com/api. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:4200' is therefore not allowed access." in console.
I can solve the problem if I use the following code in nginx config file on my server.The backend is designed using django.
if ($request_method = 'GET') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Credentials' 'true';
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
}
But I don't want to disturb the tha nginx config.
adapter
import DS from 'ember-data';
export default DS.RESTAdapter.extend({
host:"http://ift.tt/1mTEk1x",
});
How to send the request so that it doesn't show any error
Aucun commentaire:
Enregistrer un commentaire