autoclose fancybox jquery ajax

709 views
Skip to first unread message

Marco

unread,
Dec 4, 2011, 5:42:29 PM12/4/11
to fancybox
Hello,

i have a page that uses jquery to trigger an ajax request when
changing a text field in a form :


$("#kaEmail").change(function() {
$.fancybox.showActivity();
$.ajax({
type : "POST",
cache : false,
url : "checkEmail.php",
data : $(this).serializeArray(),
success : function(data) {
$.fancybox(data);
}
});

the data returned with the php file 'checkEmail.php' is shown in a
fancybox that can be closed by clicking on it.

what i need is to close it automaticly after 2 seconds

i found a tutorial online where the following is suggested :

$('a.fancydialog').fancybox({
callbackOnShow: function () {
setTimeout ('$.fn.fancybox.close ()', 2000);
}
});

i think i understand what the above means but i don't know where and
how i have to implement the 'callbackOnShow' in the jquery - ajax part
i'm now working with?

thanks for everyone willing to show me the light :)

Marco

JFK

unread,
Dec 4, 2011, 8:26:38 PM12/4/11
to fancybox
I am assuming that you are using fancybox v1.3.4
if so, try modifying your ajax call this way:

$.ajax({
type: "POST",
cache: false,
url:"checkEmail.php",
data: $(this).serializeArray(),
success: function(data) {

$.fancybox(data,{
'onComplete': function(){
setTimeout( function() {$.fancybox.close(); },10000);
} // onComplete
}); //fancybox
} // success
}); // ajax

the 'callbackOnShow' option is for ver 1.2.x

Marco

unread,
Dec 5, 2011, 5:46:53 AM12/5/11
to fancybox
JFK you showed me the light, works perfect

seemed i had the correct pieces to the puzzle just didn't know how to
put it together

thanks again

gr

Marco

Reply all
Reply to author
Forward
0 new messages