开发者

Submiting a form in a fancybox

开发者 https://www.devze.com 2023-03-18 18:56 出处:网络
Is it possible to create a form to be submitted within a fancybox. <a class=\"assignScoreValues开发者_开发百科\" href=\"/quality/assign-score-values/id/1\">Assign Score Values</a>

Is it possible to create a form to be submitted within a fancybox.

<a class="assignScoreValues开发者_开发百科" href="/quality/assign-score-values/id/1">Assign Score Values</a>

Then in the controller I display a form to be submitted. I can't redirect as I will lose the information on the original page.

I'm thinking that it's not possible?


You can submit the form with AJAX using Jquery and serializeArray(). To use an HTML link for for submission:

<a onclick="var data=jQuery('#form_id').serializeArray();
            $.ajax(
            {
                url:'url/to/post',
                type:'POST',
                data:data,
                success:
                    function(data){
                        //do something on success, for example close fancybox:
                        $.fancybox.close();
                }
            });
            return false;
            "
href="javascript:void(0);">Save Form</a>


Fancybox window is a part of the HTML of a parent one. So if your fancybox don't consist of the iframe the submitting in the fancybox will reload your parent page.

So the obvious (and the only I think) way to submit form correctly is to do it via AJAX. Then you can close the fancybox using $.fancybox.close() method.

0

精彩评论

暂无评论...
验证码 换一张
取 消