简体   繁体   中英

how to get parameter value in codeigniter controller?

am using ajax call function in codeigniter view.php

$.ajax({            
    type: 'post',
    url: '../user_controller/insert_user',
    data: { username : $("#name").val(), },
    success: function(data)
    {
        alert(data);
    }       
});

I want value of 'username' parameter in controller, how can I get this value?

$.ajax({            
            type: 'post',
            url: '../user_controller/insert_user',
            data: { 'username' : $("#name").val()},
            success: function(data)
            {
                alert(data);
            }       
        });

in user_controller/insert_user action

In core php

echo $_POST['username'];

OR as in CI

$this->input->post('username');

Will give you the value of username

http://ellislab.com/codeigniter/user-guide/libraries/input.html

$this->input->post('username');

You can also use $_POST['username'] but they don't suggest that, plus you should always use if (isset($_POST['username'])) or if (!empty($_POST['username'])) in PHP.

you can try like this in your controller

function insert_user(){
  $user=$this->input->post('username');
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM