[英]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.