On the one page, I am trying to use ajax to edit existing values. I am doing this by using jQuery Inline Edit and posting away the new data, updating the record and returning with success.
在一个页面上,我试图使用ajax来编辑现有值。我这样做是通过使用jQuery内联编辑并发布新数据,更新记录并返回成功。
This is working fine.
这工作正常。
Next I have implemented the ability to add new records, to do this I have a form at the end of the table, which submits post data then redirects back to the original page.
接下来我已经实现了添加新记录的功能,为此我在表的末尾有一个表单,它提交发布数据然后重定向回原始页面。
Each of them work individually, but after I have used the form to add a new record, the inline editing stops to work. If I close the webpage and reopen it, it works fine again until I have used the form and it goes of the rails again.
它们中的每一个都单独工作,但在我使用表单添加新记录后,内联编辑停止工作。如果我关闭网页并重新打开它,它再次正常工作,直到我使用该表格,它再次进入轨道。
I have tried a number of solutions, clearing session data, giving the form a separate name, redirecting to an alternative page (which does work, but is not ideal as I want the form to redirect back to the original location ).
我已经尝试了许多解决方案,清除会话数据,给表单一个单独的名称,重定向到一个替代页面(这确实有效,但不理想,因为我希望表单重定向回原始位置)。
Here is a sample of the view form data:
以下是视图表单数据的示例:
<?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(); ?>
This is the javascript initialisation code:
这是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' }
});
});
If I can provide any more information to clarify what I have attempted etc, let me know.
如果我可以提供更多信息来澄清我的尝试等,请告诉我。
Temporary Fix
临时修复
It seems I have come up with a work around, not ideal as I still am not sure what is causing the issue.
我似乎想出了一个解决方案,并不理想,因为我仍然不确定导致问题的原因。
I have created a method called redirect.
我创建了一个名为redirect的方法。
public function redirect(){
redirect('');
}
am now calling that after the form submit which has temporarily allows my multiple post submits to work.
我现在在表单提交后调用,暂时允许我的多个帖子提交工作。
2 个解决方案
#1
0
please try and see by replacing the jquery sign.
请尝试通过替换jquery标志来查看。
$ should be replaced by jQuery then it will create new instance to work fine
$应该被jQuery取代然后它将创建新的实例以正常工作
#2
0
I heard somewhere that jquery wont work if you put the form inside the table tag. It need to be outside the table as in:
我听说如果你把表单放在table标签里面,那jquery就不会工作了。它需要在桌子之外,如:
<form>
<table>
...
</table>
</form>
jQuery does not bring the contents of a form element if inside a table element on an ajax load
如果在ajax加载的表元素中,jQuery不会带来表单元素的内容
After testing it, i've discover that it is partialy true, (aka un-reliable)... It's the reason why i stopped using tables.
在测试之后,我发现它是部分真实的,(又名不可靠)......这就是我停止使用表格的原因。
#1
0
please try and see by replacing the jquery sign.
请尝试通过替换jquery标志来查看。
$ should be replaced by jQuery then it will create new instance to work fine
$应该被jQuery取代然后它将创建新的实例以正常工作
#2
0
I heard somewhere that jquery wont work if you put the form inside the table tag. It need to be outside the table as in:
我听说如果你把表单放在table标签里面,那jquery就不会工作了。它需要在桌子之外,如:
<form>
<table>
...
</table>
</form>
jQuery does not bring the contents of a form element if inside a table element on an ajax load
如果在ajax加载的表元素中,jQuery不会带来表单元素的内容
After testing it, i've discover that it is partialy true, (aka un-reliable)... It's the reason why i stopped using tables.
在测试之后,我发现它是部分真实的,(又名不可靠)......这就是我停止使用表格的原因。