Can't get form data to post via AJAX using Fancybox

前端 未结 1 1592
不知归路
不知归路 2021-01-16 06:59

I\'m using Fancybox to have a contact form pop up when a link is clicked. Then it POSTs the form data to a php file, an email goes out and a success message comes back.

相关标签:
1条回答
  • 2021-01-16 07:44

    It was a simple mistake, I was putting the script above in its own <script> tags instead of in the main fancybox attach script. My final code is:

    <script type="text/javascript">
    $(document).ready(function(){
        $("a.lightbox").fancybox({
            'transitionIn'  :   'fade',
            'transitionOut' :   'fade',
            'speedIn'       :   600, 
            'speedOut'      :   200, 
            'overlayShow'   :   false
        });
    
        $("#question-form").bind("submit", function() {
    
            $.fancybox.showActivity();
    
            $.ajax({
                type        : "POST",
                cache       : false,
                url         : "/includes/question-mailer.php",
                data        : $(this).serializeArray(),
                success     :function(data){
                                $.fancybox(data);
                             }
            });
    
            return false;
        });
    
    });     
    </script>
    
    0 讨论(0)
提交回复
热议问题