Доступ к XMLHttpRequest в 'http://localhost/PostgresSample/persons'(Php Rest api) из источника' null 'был заблокирован политикой CORS: - PullRequest
0 голосов
/ 11 марта 2019

как я могу это исправить?

вот некоторые из моих кодов в остальных API

public function getPersons($id = NULL){
    header('Access-Control-Allow-Headers: Client-Service,Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
    header('Content-Type: application/json');
    header('Access-Control-Allow-Origin: *');
    header('Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE, PUT');

    echo $this->input->get_request_header('Client-Service',TRUE);
    if ($this->authentication->check_auth()){
      json_output(401,array('status'=> 404,'message' =>'Unauthorized'));
      return;
    }
    //more code

, и это код в клиенте

 var headers = {
        'Content-Type': 'application/json',
        'Client-Service': 'love',
        withCredentials: true,
        'Access-Control-Allow-Origin': '*',
        }
  axios.get('http://localhost/PostgresSample/persons',{headers})
  .then(function (response) {
     // handle success
     console.log(response.data);
  })
  .catch(function (error) {
     // handle error
     console.log(error);
  })
  .then(function () {
     // always executed
  });

В сети так много этой проблемы, но я не могу найти, что исправляет мою.Заранее спасибо за ответ

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...