John Smith
John Smith

Reputation: 1814

jquery fancybox close errors

Have the following in an fancybox ajax call

               $.ajax({
                    type: 'POST',
                    url: 'sendmesse.php',
                    data: $("#messform").serialize(),
                    success: function(data) {
                        if(data == "true") {
                            $("#messform").fadeOut("fast", function(){
                                $(this).before("<strong>Success! Your feedback has been sent, thanks :)</strong>");
                                setTimeout($.fancybox.close(), 1000);
                                // $('.fancybox').close();
                                // $.fancybox.close();

                            });
                        }
                    }
                });

all works fine appart from the closing, tried various variations without sucess. The timeout above gives me Error: useless setTimeout call (missing quotes around argument?)

so i tried both setTimeout('$.fancybox.close()', 1000); and setTimeout("$.fancybox.close()", 1000); to which i get the following error TypeError: $ is undefined

...help !

Upvotes: 0

Views: 897

Answers (3)

Shih-En Chou
Shih-En Chou

Reputation: 4165

Try as shown below:

setTimeout(function(){ $.fancybox.close();}, 1000);

Upvotes: 1

Brian Scott
Brian Scott

Reputation: 9361

Try creation a simple function called "closeMyFancyBox" such as

function closeMyFancyBox() {
$.fancybox.close();
}

Then call that function as setTimeout('closeMyFancyBox', 1000);

Upvotes: 0

pankar
pankar

Reputation: 1701

setTimeout expects either a function reference or a string to evaluate. In your case try calling setTimeout like:

setTimeout(function() { $.fancybox.close(); }, 1000);

Upvotes: 1

Related Questions