I am currently working on my first app using ionic
with a codeigniter backend. However, I am encountering the "Response for preflight has invalid HTTP status code 405" issue in ionic
+ CI backend. Can anyone help me solve this problem?
This is my 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
});
});
};
Here is my webapi code in codeigniter:
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);
}
}