Post JSON to Codeigniter controller

后端 未结 12 1019
鱼传尺愫
鱼传尺愫 2020-12-30 05:03

I am trying to receive and parse a JSON object sent in a POST request using Codeigniter but I cannot \"find\" it.

This is my controller code:

public          


        
12条回答
  •  孤城傲影
    2020-12-30 05:13

    Are you sure you're POSTing the data and not doing a GET instead? I ran into this issue earlier today (which is how I found this question) and I was doing a POST but using JSONP which seems to be done with a GET.

    CodeIgniter has a function called get_post that will get the data from wherever it happens to be.

    $this->input->get_post_string('data'); 
    

    I hope this helps you out.

    You can do it manually like so if you'd like.

    function get_post($index = '', $xss_clean = FALSE){
        if ( ! isset($_POST[$index]) )
        {
            return $this->get($index, $xss_clean);
        }
        else
        {
            return $this->post($index, $xss_clean);
        }
    }
    

提交回复
热议问题