0

我的目标是通过 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!

4

1 回答 1

0

我知道了!

  $(document).ready(function(){

               function prepform(){

                    $('#Form_PlayerSave<?= $x ?>').ajaxForm({
                               // target identifies the element(s) to update with the server response

                               beforeSubmit:  CPshowRequest<?= $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: CPshowResponse<?= $x ?>,
                               resetForm: true

                   });

               }

               $(".customPlan<?= $x; ?>").colorbox({inline:true, href:"#customPlanDiv<?= $x; ?>"}, prepform);

         });

            // pre-submit callback
            function CPshowRequest<?= $x ?>(formData, jqForm) {
                var x = $('#percentage<?= $x ?>').fieldValue();
                $('#custom_plan_text<?= $x ?>').html(x[0]);
                return true;
            }
            function CPshowResponse<?= $x ?>(responseText, statusText, xhr, $form)  {
                $.fn.colorbox({html:"Custom Plan Saved", open:true});
            }

为什么这能打动我,但确实如此。:)

此外,对于未来的旁观者,要确保 div 不会在提交时被替换,只需确保 target 不指向您原始表单的 div(我的部分愚蠢愚蠢)。

于 2010-12-11T21:31:45.690 回答