CI 3 没有从 ajax 接收任何数据,即使它成功了



这是我的ajax

var data = {
user_id : <?php echo $this->session->userdata('id') ?>,
no_s0 : $('#no_so').val(),
catatan : $('#remarks').val(),
kode_barang : $('#kode_barang').val(),
nama_toko : $('input[id="nama_toko"]').map(function(){return $(this).val()}).get(),
pcs : $('input[id="pcs"]').map(function(){return $(this).val()}).get(),
diskon : $('input[id="diskon"]').map(function(){return $(this).val()}).get()
}
$.ajax({
url : '<?php echo base_url('sales_so/input') ?>',
type : 'POST',
data : data,
error : function(){
alert('gagal')
},
success : ()=>{
alert('berhasil')
}
})

状态代码是200,运行良好。问题是我没有从中得到任何数据。我试图对数据进行var_dump,但它给了我以下信息:array(0({}

这是我的控制器:

$post = $this->input->post();
var_dump($post);

编辑:请帮忙,我仍然找不到解决方案。

您可以使用serializeArray

fields = $ ("#element").serializeArray();

将其放入控制器时会发生什么?

$post = json_decode(file_get_contents("php://input"));
var_dump($post);

对不起我的英语,

我假设你想发送的数据来自表单提交,如果是真的,它可以像这个一样简单

var form = new FormData($("#id_form")[0]); // make sure to use the id on the form
$.ajax({  
type: "POST",  
url:  <?php echo base_url('sales_so/input') ?>, 
data: form,  
processData: false,
contentType: false,
success: function(result){
console.log(result); // for debugging can be seen on the console. or you can also use alert alert('sukses');
}
});

在控制器中尝试var_dump结果

谢谢。

最新更新