[英]CodeIgniter refresh page after form submit
我正在尝试通过CodeIgniter刷新页面,但似乎无法正常工作。
基本上,我们在页面上有一个作业列表,用户可以选择过滤所述作业。
因此,用户将选择复选框,然后单击“保存”以根据其用户ID将其选择保存到数据库中。
一旦他们保存了选择,我显然需要刷新数据,但是我尝试了很多事情,但这似乎根本不起作用。 我假设我将重定向放在错误的位置,该位置当前在控制器中。
我尝试了以下方法:
$this->load->helper('url');
redirect('dashboard', 'refresh');
但是什么也没发生。
我在控制器功能中具有上述重定向:
public function save_filters() {
if (isset($_POST)){
$filters = $_POST['client_ids'];
}
$this->load->model('dashboard_model');
$this->dashboard_model->update_dashboard_filters($filters);
$this->load->helper('url');
redirect('dashboard', 'refresh');
}
我把它放错了地方吗?
我没有收到来自萤火虫的错误或警告吗?
表格:
<form id="filters_form">
<table>
<tr>
<td>
<label for="GAB Robins">GAB Robins </label><input type="checkbox" name="client_ids[]" value="4">
</td>
<td>
<label for="Cunningham Lindsay">Cunningham Lindsay </label><input type="checkbox" name="client_ids[]" value="5">
</td>
<td>
<label for="Lloyds">Lloyds </label><input type="checkbox" name="client_ids[]" value="7">
</td>
<td>
<label for="Sundry/Private">Sundry/Private </label><input type="checkbox" name="client_ids[]" value="9">
</td>
<td>
<label for="WNS Ltd">WNS Ltd </label><input type="checkbox" name="client_ids[]" value="4441">
</td>
<td>
<label for="Stream">Stream </label><input type="checkbox" name="client_ids[]" value="4493">
</td>
<td>
<label for="Redesign">Redesign </label><input type="checkbox" name="client_ids[]" value="5295">
</td>
</tr>
</table>
<input type="button" value="Save selections" name="save_filters" id="save_filters_button" />
</form>
处理表单的javascript
save_filter: function () {
$.post('/dashboard/save_filters', $('#filters_form').serialize(), function (response) {
if (response.status == 'ok') {
if ($('.ui-success').length == 0) {
$('#page_main').before('<div class="ui-success" style="margin-bottom: 1em; font-weight: bold; border-bottom: 1px solid #ccc; padding: 1em;"><img src="/common/images/icons/accept.png" style="margin-right: 10px;" align="absmiddle" />Filters saved!</div>').fadeIn(1000);
}
}
else {
$(response.errors).each(function (i, item) {
alert(item);
});
}
});
}
将动作放入以下形式: action="<?php base_url(); ?>controller_name/function_name"
和method="post"
例:
<form id="filters_form" action="<?php base_url(); ?>controller_name/function_name" method="post">
更新:因为您使用的是JS,所以您没有刷新页面。 如果要刷新页面,请不要使用JS。
它不起作用,因为您有一个Ajax请求,并且在将数据返回到发出该请求的JavaScript之前,无法在服务器上进行重定向。
您可以根据您的回复进行重定向
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.