Thursday, March 22, 2012

For fixing facebox loading content twice in it, after calling ajax/jquery content

We have a facebox popup which will show when click on a link from the top of the page.

We have also facebox popup which is inside a product listing. After replacing the content in the product list using jquery/ajax we have to reinitialize the facebox to work the popup in the list.

for it we use:

$.post(abc.com/fun.php",{sort:sort_field},function (data){   
                           
                $("#tbl_product_list tbody").html(data);
                $('a[rel*=modal]').facebox() ;
            });

Now the when click on the first facebox at the first facebox from the link, we can see the content is twice in it. this is because the facebox initializing twice.

For avoiding this, we can use a different rel in facebox links which is loading by ajax/jquery like

<a href="pop.php"  rel="tests">

now the above function will need to change like


 $.post(abc.com/fun.php",{sort:sort_field},function (data){   
                           
                $("#tbl_product_list tbody").html(data);
                $('a[rel*=tests]').facebox() ;
            });

 

No comments:

Post a Comment