[英]Ajax post to CodeIgniter controller not working
我正在尝试将一些数据发布到CodeIgniter控制器,但它仅显示空数组。 我也在使用DataTables。 我不确定我是否以正确的方式发送数据。 这是我的代码:
JS
$("#prw").on('click', function(e){
e.preventDefault();
var url = window.location.origin + "/nsl/preview";
$.ajax({
url: url,
data: $("input[type='checkbox']:checked").serialize()
}).done(function(data){
console.log("Response", data);
});
});
控制器
function preview() {
$post = $this->input->post();
return $post;
}
的HTML
<table id="offers" class="table table-striped table-bordered" cellspacing="0" width="100%">
<thead>
<tr>
<th>...</th>
<th>...</th>
<th>...</th>
<th>...</th>
<th>...</th>
</tr>
</thead>
<tfoot>
<tr>
<th>...</th>
<th>...</th>
<th>...</th>
<th>...</th>
<th>...</th>
</tr>
</tfoot>
<tbody>
<?php foreach($data as $d): ?>
<tr>
<td><input type="checkbox" id="check" name="myCheckboxes[]" class="toggle" value="<?=$d->oid?>"></td>
<td><input type="text" id="rb" name="myText[]" class="toggle"></td>
<td><?=$d->fullname?></td>
<td><?=$d->published?></td>
<td><?=$d->expires?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<input type="submit" id="prw" class="btn btn-info" value="Preview">
请给我任何帮助。
要检查的某些事情:-
在ajax调用中,提及type : 'post'
点击功能,请尝试
alert($(“ input [type ='checkbox']:checked”)。serialize());
并检查您是否获得了预期的值?
打开Firebug,在控制台上单击,执行单击按钮,查看控制台内URL的POST选项卡下的所有值。
控制器内部
$ post = $ this-> input-> post('myCheckboxes'); print_r($ post);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.