[英]How to pass variable serialize through ajax to codeigniter controller?
My view: 我的观点:
$('#frm_ingreso').submit(function(e) {
$.ajax({
url: `${RUTA}retaso-ingreso/guardar`,
type: 'POST',
data: {
"data": $('#frm_ingreso').serialize()
},
})
.done((response) => {
console.log(response);
});
e.preventDefault();
return false;
});
My Controller: 我的控制器:
I show all post with print_r($_POST)
and it´s shown, but when I want to pass variable each data: 我显示了所有带有
print_r($_POST)
帖子,并显示了它,但是当我想传递变量每个数据时:
public function guardar(){
print_r($_POST);
/*
Array
(
[data] =>
cboMaterial=2&cboTipo=3&cboColor=2
)
*/
$material = $this->input->post("cboMaterial"); // error it's show nothing
echo $material; // its show nothing
}
You should do this: 你应该做这个:
data: $('#frm_ingreso').serialize()
Usage: 用法:
$('#frm_ingreso').submit(function(e) {
$.ajax({
url: `${RUTA}retaso-ingreso/guardar`,
type: 'POST',
data: $('#frm_ingreso').serialize(),
})
.done((response) => {
console.log(response);
});
e.preventDefault();
return false;
});
and $material = $this->input->post("cboMaterial");
和
$material = $this->input->post("cboMaterial");
should work 应该管用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.