fancybox links doesn't work on inside ajax content

∥☆過路亽.° 提交于 2019-12-24 07:29:10

问题


I need to update a section on my site frequently using ajax, jquery, and php.

When the page first loads, it calls a javascript function that displays the content of that section. Then using json I check for updates and if there are results, calls the same function to display it.

Now inside the ajax content there are links like

<a href="news.php?id" class="ajaxpopup">title</a>

to call fancybox but instead of opening a popup, it opens the page directly. If the link to call fancybox is not inside an ajax content it displays properly. I know that there are some people with the same problem but the answers are for divs with specific id. How can I set it globally. I mean to work on links with class="ajaxpopup"?

this is my function to call the content

$(document).ready(function() {
  $(".ajaxpopup").fancybox({
    'overlayColor'      : '#000000', 
    'centerOnScroll'    : true,
    'transitionIn'      : 'none',
    'transitionOut'     : 'none',
    'modal'             : true
  }); 
});

function update(page,value)    {
  var data = 'id='+value;
  $.ajax({
    url: page,
    type: "POST",       
    data: data,     
    cache: false,
    success: function (html) {  
      $('#updates').html(html);   
      $('#updates').fadeIn(200);      
    }       
  });
}

then the divs


回答1:


After loading the dynamic content, bind the fancy box again

 div.load("myserverpage.aspx?mode=popularmodels", { symbol: $("#txtSymbol").val() }, function() {
                $(this).fadeIn(100);

                $(".ajaxpopup").fancybox({
                    'scrolling': 'no',
                    'titleShow': true,
                    'titlePosition': 'over',
                    'onClosed': function () {
                        $("#login_error").hide();
                    }
                });
            });


来源:https://stackoverflow.com/questions/8853717/fancybox-links-doesnt-work-on-inside-ajax-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!