Fancybox afterLoad Callback

Fancy box load on ajax success call

On load of a fancybox from ajax, return a function to listen on the element in fancybox.

jQuery(document).ready(function (submit) {
    $('#check').on("click", function (e) {
        e.preventDefault();
        $.ajax({
            type: "POST",
            cache: false,
            url: "/echo/html",
            data: $("#result").serializeArray(),
            success: function (data) {
                // on success, post returned data in fancybox
                $.fancybox(echoData, {
                    // fancybox API options
                    fitToView: true,
                    openEffect: 'fade',
                    closeEffect: 'fade',
                    afterLoad: function () {
                        return fancyUpdateMyWay = function () {
                            var a = Math.random();
                            var newHtml = "<h4>UPDATED: Result of search now=" + a + "</h4>";
                            $("#fancyResult").html(newHtml);

                        }

                    }

                });
            }
        });
    });
});
DEMO
Fancybox afterLoad Callback Fancybox afterLoad Callback Reviewed by Bhaumik Patel on 8:24 PM Rating: 5