我正在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')); –