Answer the question
In order to leave comments, you need to log in
Crossdomain ajax request - what could be the problem?
What we are dealing with:
- Angular on the frontend (to be more precise, Restangular, but it uses Angular.$http)
- Yii on the backend (actually, this is not so important) I am
trying to send a request to manager.rfx.dev api.rfx.dev . (local domains)
I spice up Angular with the following headers:
RestangularProvider.setDefaultHeaders({
'Content-Type': 'application/json',
'X-Requested-With': 'XMLHttpRequest'
});
RestangularProvider.setDefaultHttpFields({
'withCredentials': true
});
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header('Access-Control-Request-Headers: Accept, X-Requested-With');
header('Access-Control-Allow-Credentials: true');
OPTIONS api.rfx.dev/contexts 403 (Forbidden) angular.min.js:73
OPTIONS api.rfx.dev/contexts No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' manager.rfx.dev ' is therefore not allowed access. angular.min.js:73
XMLHttpRequest cannot load api.rfx.dev/contexts. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' manager.rfx.dev ' is therefore not allowed access.
Answer the question
In order to leave comments, you need to log in
For cross-domain requests with withCredentials: true , the Access-Control-Allow-Origin header must be set to a specific value, the asterisk is invalid.
Instead header('Access-Control-Allow-Origin: *');
try
header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question