数据表Ajax请求进入Codeigniter控制器

时间:2017-03-15 18:42:30

标签: php jquery ajax codeigniter

我正在尝试通过AJAX数据发送此网址www.example.com/country/AF.html的最后一个值( af ),并希望在Codeigniter Controller中读取此数据,但无法检索数据。请帮忙

Datatable Ajax Code

$(document).ready(function() {
    var UserURL = window.location.href.split("/").pop();
    var newurl = UserURL.split("/").slice(-1).join().split(".").shift();
    $('#countryiptable').DataTable({
        "pageLength": 50,
        "info": false,
        "processing": true,
        "serverSide": true,
        'ajax': {
            'url': "country/getlist",
            "type": "POST",
            "data":{"country_code": newurl},
            "dataType": "json",
            "dataSrc": function (jsonData){
                return jsonData.data;
            }
        }
    });
} );

这是我的Codeigniter控制器;

    public function getlist(){

        echo $this->input->post('country_code');
        $countryiso2    = strtoupper($this->input->post('country_code'));       
        //echo "hi";
        $list = $this->CountryModel->getCountry($countryiso2);

        $data = array();
        $no = $_POST['start'];
        foreach ($list as $iplist) {
        // print_r($data);die;
        $no++;
        $row = array();
        $row[] = $no;
        $row[] = $iplist->startip;
        $row[] = $iplist->registry_name;
        $row[] = $iplist->totalip;
        $row[] = $iplist->country_code;
        $row[] = $iplist->ip_type;

        $data[] = $row;

        //$_POST['draw']='';
        }

        $output = array(
            "draw" => $_POST['draw'],
            "recordsTotal" => $this->CountryModel->count_all(),
            "recordsFiltered" => $this->CountryModel->count_filtered(),
            "data" => $data,
        );
        //output to json format
       echo json_encode($output);
    }
}

0 个答案:

没有答案