Skip to content Skip to sidebar Skip to footer

Colorbox And Content Returned Via Ajax

I'm using jquery colorbox to popup user accounts in a window. I also have a button that loads more users into the page via ajax, but for some reason users loaded with ajax do not p

Solution 1:

If you want to make it work globally, regardless of how the content is loaded:

$('body').on('click', 'a.usr', function() {
    $(this).colorbox({width:"960px", height:"90%", iframe:true});
});

Solution 2:

When you bind colorbox in $(document).ready() with this:

$("a.usr").colorbox({width:"960px", height:"90%", iframe:true});

jQuery will go search through the page, grab everything that matches a.usr, bind colorbox to those items, and then forget all about a.usr. jQuery won't remember that you're interested in a.usr so the new ones won't be colorbox'd.

The usual solution to this sort of thing is to use .live() or .delegate() but those won't work here as there isn't a "colorbox" event.

However, you can bind colorbox by hand easily enough. Try change loadMore to something more like this:

functionloadMore(pageNo) {
    $.get('/search/resultsAjax', { page: pageNo }, function(response) {
        var $html = $(response);
        $html.find('a.usr').colorbox({ width: '960px', height: '90%', iframe: true });
        $('#results').append($html);
    };
}

You just turn the response HTML into a jQuery object, find all the a.usr things inside it, bind colorbox to those, and then insert the new HTML into the DOM as usual.

Solution 3:

Use this:

<aonclick='parent.$.colorbox({href:"schedule_delete.php?sid=<?phpecho$schedule_row->schedule_id; ?>"}); return false;'>delete</a

Post a Comment for "Colorbox And Content Returned Via Ajax"