【发布时间】:2016-03-07 14:36:12
【问题描述】:
我有 CodeIgniter 的问题。如何将数组从视图传递到控制器?
我无法通过单击按钮调用公共函数sms() 从视图向控制器发送数据。
这是我的代码不起作用:
<script>
function send_sms() {
var chkBoxArray = new Array();
$(document).ready(function (e) {
$('#table input[type="checkbox"]:checked').each(function () {
var getRow = $(this).parents('tr');
chkBoxArray.push(getRow.find('td:eq(9)').html());
});
alert(chkBoxArray);
reload_table();
});
$.ajax({
url: "<?php echo site_url('person/sms')?>",
type: "POST",
data: { 'arr': chkBoxArray },
dataType: "JSON",
success: function (data) {
// if success reload ajax table
// alert(chkBoxArray);
// reload_table();
},
error: function (jqXHR, textStatus, errorThrown) {
alert('Error adding / update data');
}
});
}
</script>
控制器代码:
public function sms() {
$arr = $this->post('arr');
foreach($arr as $ar) {
echo $ar; // prints each element of the array.
}
}
【问题讨论】:
-
不清楚具体是什么问题。 “不起作用” 是一个毫无意义的问题陈述,并不表明哪个部分不起作用
-
先试试
data: { arr: chkBoxArray },。
标签: php jquery ajax codeigniter