dongliqin6939 2016-12-27 12:52
浏览 37

没有得到angularjs发布数据在控制器(codeigniter)

I am making a HTTP request to a url, in which the data is getting post in request headers, but when I am fetching it in controller using the $this->input->post, it is showing blank.

Angularjs code :

//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;
       }
   });
}

Controller Function :

 function sendresultemail(){
         $from_email = "test@test.com"; 
//         $to_email = $this->input->post('email'); 
         $to_email = "abc@gmail.com"; 

         $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');

         }

    }

Refer below images, in screen1

you can see the data in request payload, but in the response it is showing blank screen2

  • 写回答

3条回答 默认 最新

  • dphphvs496524 2016-12-27 13:13
    关注

    You didn't mention header content type.

    $scope.processresult=function(){
                        $http({
                            method:"POST",
                           url:"http://localhost/quizci/admin/sendresultemail/",
                           headers: {'Content-Type': 'application/x-www-form-urlencoded'},
                            data:{
                                "riskscore":$scope.datascore
                            },
                        })
    

    In php.. ex..

    public function store()
    {
        $this->load->database();
        $_POST = json_decode(file_get_contents('php://input'), true);
        $posts = $this->input->post();
        $this->db->insert('posts', $posts);
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度