预检响应在 ionic + CI 后端中具有无效的 HTTP 状态代码 405

Response for preflight has invalid HTTP status code 405 in ionic + CI backend

我正在尝试在 ionic 中开发第一个应用程序并使用 codeigniter 后端,但在 ionic + CI 后端问题中面临预​​检响应无效的 HTTP 状态代码 405 问题帮助我解决这个问题。

我的controller.js:

.controller('SingUpCtrl',function($scope,$http){
$scope.signup_cancel = function (){
$state.go('app.login');
};

$scope.signUp=function(){
$scope.data = {};
var postData = {
  "user_first_name":$scope.data.user_first_name,
  "user_last_name" :$scope.data.user_last_name,
  "user_gender" :$scope.data.user_gender,
  "user_dob" :$scope.data.user_dob,
  "user_email" :$scope.data.user_email,
  "user_password" :$scope.data.user_password
};

var link = 'http://maghnusideas.com/ionic/index.php/api/places/user';
var header={
  "cache-control": "no-cache",
      "postman-token": "6cfae124-631b-9367-89c7-04c0a12ab489"
}
$http.post(link, postData,header).then(function (res){
  console.log('success');
  var json_obj = JSON.stringify(res.data);
  json_obj = JSON.parse(json_obj);
  $ionicPopup.alert({
    template: json_obj.message
  });

});
};

我在 codeigniter 中的 webapi 代码:

public function user_post()
{
    $this->load->library('form_validation');
    $this->load->model('Admin_model');

    $this->form_validation->set_rules('first_name', 'First Name', 'required');
    $this->form_validation->set_rules('last_name', 'Last Name', 'required');
    $this->form_validation->set_rules('gender', 'Gender', 'required');
    $this->form_validation->set_rules('dob', 'Date of Birth', 'required');
    $this->form_validation->set_rules('email', 'Email', 'required|valid_email');
    $this->form_validation->set_rules('password', 'Password', 'required');

    if($this->form_validation->run())
    {
        $first_name=$this->input->post('first_name');
        $last_name=$this->input->post('last_name');
        $gender=$this->input->post('gender');
        $dob=$this->input->post('dob');
        $email=$this->input->post('email');
        $password=$this->input->post('password');
    }
    else{
        $this->set_response('Failure to add', REST_Controller::HTTP_BAD_REQUEST);
    }

    $result=$this->Admin_model->insert('tbl_user',array('user_first_name'=>$first_name,'user_last_name'=>$last_name,'user_gender'=>$gender,'user_dob'=>$dob,'user_email'=>$email,'user_password'=>$password));
    if($result)
    {
        $this->set_response('User Registered Successfully...!', REST_Controller::HTTP_OK);


    }else
    {
        $this->set_response('Inserted Data not Proper', REST_Controller::HTTP_BAD_REQUEST);

    }
}

此错误与 CORS 有关 要解决此问题,您可以使用离子代理功能 - 请参阅 http://ionicinaction.com/blog/how-to-fix-cors-issues-revisited/ 或者在这里 http://blog.ionic.io/handling-cors-issues-in-ionic/