Calling jQuery Form ajaxSubmit more than once fails

191 Views Asked by At

I have a form that has a "Preview" button, which submits the form contents to a preview page using jQuery form ajaxSubmit and the success callback function shows the contents of that request in a fancybox, the "Continue" button is used to submit the form normally and go continue to a second page.

All this works as expected on the first click of "Preview", I then close the fancybox, then on subsequent clicks of "Preview", I get the error shown.

Any ideas this has been driving me crazy for hours.

I am using jQuery 1.10.2 and jQuery Form Plugin 3.51.0 and jQuery Fancybox 2.1.5.

    function successFunction(responseText)
    {
        $.fancybox({
            'content' : responseText
        });
    }

    $(document).ready(function() {
        var ajaxFormOptions = {
            success: successFunction,  // post-submit callback
            url:     '{{ path('StarthereRewardsfromusBundle_preview1') }}'         // override for form's 'action' attribute
        };

        $('form').click(function(event) {
            if (event.target.innerHTML == "Preview")
            {
                $(this).ajaxSubmit(ajaxFormOptions);
                return false;
            }
            else if (event.target.innerHTML.indexOf("Continue") == 0)
            {

            }
        });
    });

Error

Thanks in advance...I hope :-)

0

There are 0 best solutions below