简体   繁体   中英

How can i post value from Ajax to Controller (Codeigniter)

Post data includes that name and surname. These datas are posted (show request console) but firebug give me 404 error about "POST localhost/index.php/getdata/ 404 Not Found"

function gonder(){
    $.ajax({
        type:'POST',
        url:'/index.php/getdata/',
        data:$('#form1').serialize(),
        success: function (msg) {
            $('#yaz').html(msg);
            $('#btn').removeAttr('disabled');
        }
    });
}

public function getdata()
    {
        $this->output->set_content_type('application/json');
        if ( ! isset($_POST['data']))
        {
            $data = FALSE;
        }
        else
        {
            $data = $_POST['data'];
        }
        $this->load->view("getdata_view");
        $data = $this->input->post('data');
        var_dump($data);
    }

Check your path..is '/index.php/getdata/' the right path?

It should be /index.php/yourcontrollername/yourmethodname(getdata in your case).

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