0

尝试使用 ajax 和 php 向 mysql 发送参数?我以前在我的项目中做过这个,但由于某种原因这不起作用

看法 :

$(document).on('click','#btnbehvoegtoe',function(){

            var klacht = $('#lijstbeh_klacht').val();
            var diagnose = $('#lijstbeh_diagnose').val();
            var beh = $('#lijstbeh_behandeling').val();
            var behkort = $('#lijstbeh_behandelingkort').val();
            alert(patid);
            alert(klacht + diagnose + beh + behkort);



            $.ajax({
                type: 'POST',
                url: 'behandelingen/addbehandeling',
                datatype : 'JSON',
                data: { BEH_PA_ID : patid,
                        BEH_klacht : klacht,
                        BEH_diagnose : diagnose,
                        BEH_behandeling : beh,
                        BEH_behandelingkort : behkort
                },
                success : function(){
                    alert("De behandeling is toegevoegd");
                }
            });
        });

控制器

public function addbehandeling()
{
    $this->load->model('behandelingen_model');
    $this->behandelingen_model->addbehandeling();

}

模型

function addbehandeling()
{
$BEH_PA_ID = $this->security->xss_clean($this->input->post('BEH_PA_ID'));
$BEH_klacht = $this->security->xss_clean($this->input->post('BEH_klacht'));
$BEH_diagnose = $this->security->xss_clean($this->input->post('BEH_diagnose'));
$BEH_behandeling = $this->security->xss_clean($this->input->post('BEH_behandeling'));
$BEH_behandelingkort = $this->security->xss_clean($this->input->post('BEH_behandelingkort'));
$data = array(
            'BEH_PA_ID' => $BEH_PA_ID,
            'BEH_klacht' => $BEH_klacht,
            'BEH_diagnose' => $BEH_diagnose,
            'BEH_behandeling' => $BEH_behandeling,
            'BEH_behandelingkort' => $BEH_behandelingkort,
            'BEH_datum' => date('Y-m-d')
);
$this -> db -> insert('behandelingen', $data);

}

警报工作 Firebug 的参数也为 POST

4

0 回答 0