Submiting a form in a fancybox

房东的猫 提交于 2019-12-25 14:41:55

问题


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?


回答1:


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>



回答2:


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.



来源:https://stackoverflow.com/questions/6625141/submiting-a-form-in-a-fancybox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!