问题
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