我的目标是通过 ajax 在Colorbox模式中提交一个表单(该部分已完成),然后获取一个提交的值(称为“百分比”)并更新表中的值。
我在下面有我的代码(无表格)。您可以看到打开了一个链接,其中包含我的表单 (#Form_PlayerSave) 的 Div 并且该表单通过出色的jQuery Form Plugin进行了 ajaxified 。表单提交正确,现在我只想更新表格的“百分比”部分。
脚本中包含 php,因为我每页需要 25 个表单(表格的每一行一个),所以每个 $x 只计算不同的表单。
那么,我该怎么办?我下面的返回未定义,我尝试了很多不同的解决方案。
我还注意到,当再次单击表中打开 Colorbox 模式的链接时,它会显示表单通常提交到的页面,如果它没有全部 ajaxy。有关如何解决此问题的任何想法,以便用户可以将值更新为他们的小心脏内容?
$(document).ready(function(){
function prepform(){
$('#Form_PlayerSave<?= $x ?>').ajaxForm({
// target identifies the element(s) to update with the server response
target: '#customPlanDiv<?= $x; ?>',
// success identifies the function to invoke when the server response
// has been received; here we apply a fade-in effect to the new content
success: function() {
$.fn.colorbox({html:"Custom Plan Saved", open:true});
var x = $('#Form_PlayerSave<?= $x ?> :percentage').fieldValue();
$('#custom_plan_text<?= $x ?>').val(x[0]);
}
});
}
$(".customPlan<?= $x; ?>").colorbox({inline:true, href:"#customPlanDiv<?= $x; ?>"}, prepform);
});
我真的很感谢大家的帮助!谢谢* 10!