我正在HTTP请求的URL,其中,所述数据是变在请求的头部后,但是当我使用的$this->input->post
获取它在控制器,它显示空白。在控制器没有得到angularjs后数据(笨)
Angularjs代码:
//Code to send email of quiz results
$scope.processresult=function(){
$http({
method:"POST",
url:"http://localhost/quizci/admin/sendresultemail/",
data:{
"riskscore":$scope.datascore
},
})
.success(function (data) {
if (!data.success) {
// if not successful, bind errors to error variables
$scope.errorName = data.errors.name;
$scope.errorSuperhero = data.errors.superheroAlias;
}
else {
// if successful, bind success message to message
$scope.message = data.message;
}
});
}
控制器功能:
function sendresultemail(){
$from_email = "[email protected]";
// $to_email = $this->input->post('email');
$to_email = "[email protected]";
$this->load->model('user_model');
// $result = $this->user_model->get_user_by_id($this->session->userdata($sess_array['id']));
echo "risk score =".$this->input->post('riskscore');
exit;
//Load email library
$this->load->library('email');
$this->email->from($from_email, 'ERMS');
$this->email->to($to_email);
$this->email->subject('Email Test');
$this->email->message($_POST);
//Send mail
if($this->email->send()){
$this->session->set_flashdata("email_sent","Email sent successfully.");
}
else {
$this->session->set_flashdata("email_sent","Error in sending Email.");
$this->load->view('admindash');
}
}
我试过前面添加标题,但它给“不允许主要人物形象。” CI中的错误,因此我删除了该错误。 – adi
改变标题:{'Content-Type':'application/json'},并且php $ obj = json_decode(file_get_contents('php:// input')); –