在一页上,我正在尝试使用 ajax 来编辑现有值。我通过使用jQuery Inline Edit并发布新数据、更新记录并成功返回来做到这一点。
这工作正常。
接下来我实现了添加新记录的功能,为此我在表的末尾有一个表单,它提交帖子数据然后重定向回原始页面。
他们每个人都单独工作,但在我使用表单添加新记录后,内联编辑停止工作。如果我关闭网页并重新打开它,它会再次正常工作,直到我使用该表单并且它再次脱离轨道。
我尝试了许多解决方案,清除会话数据,给表单一个单独的名称,重定向到另一个页面(这确实有效,但并不理想,因为我希望表单重定向回原始位置)。
这是视图表单数据的示例:
<?php foreach($week->incomes as $income):?>
<tr>
<td><?php echo $income->name;?></td>
<td width="70" style="text-align:right;" class="editableSingle income id<?php echo $income->id;?>">$<?php echo $income->cost;?></td>
</tr>
<?php endforeach;?>
<?php echo form_open('budget/add/'.$week->id.'/income/index', 'class="form-vertical" id="add_income"'); ?>
<tr>
<td>
<input type="text" name="name" class="input-small" placeholder="Name">
<input type="text" name="cost" class="input-small" placeholder="Cost">
</td>
<td>
<button type="submit" class="btn btn-small pull-right"><i class="icon-plus "></i></button>
</td>
</tr>
<?php echo form_close(); ?>
这是javascript初始化代码:
$(function(){
$.inlineEdit({
income: 'budget/update_income/',
expense: 'budget/update_expense/'
},
{
animate: false,
filterElementValue: function($o){
if ($o.hasClass('income')) {
return $o.html().match(/\$(.+)/)[1];
}
else if ($o.hasClass('expense')) {
return $o.html().match(/\$(.+)/)[1];
}
else {
return $o.html();
}
},
afterSave: function(o){
if (o.type == 'income') {
$('.income.id' + o.id).prepend('$');
}
if (o.type == 'expense') {
$('.expense.id' + o.id).prepend('$');
}
},
colors: { error:'green' }
});
});
如果我可以提供更多信息来澄清我的尝试等,请告诉我。
临时修复
似乎我想出了一个解决方法,但并不理想,因为我仍然不确定是什么导致了这个问题。
我创建了一个名为重定向的方法。
public function redirect(){
redirect('');
}
我现在在表单提交之后调用它,它暂时允许我的多个帖子提交工作。