How to load AJAX content into current Colorbox window?

后端 未结 1 1595
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-03 00:52

I\'m searching for the answer for three days in a row already. The matter is that I have a page, links on which should load Colorbox with AJAX content that in its turn conta

1条回答
  •  借酒劲吻你
    2021-01-03 01:17

    If you need to load the content into the same Colorbox rather than opening a new instance, I would start by making sure that the event handler context to open the Colorbox was exclusive and not hooked onto the 'open_ajax' elements in the Colorbox.

    Something like this:

    
    

    If the above does not work try making the selector more specific/unique.

    Then AJAX in the new content directly into the Colorbox you already have open.

    Something like this:

    $('#cboxLoadedContent a[rel="open_ajax"]').live('click', function(e){
        // prevent default behaviour
        e.preventDefault();
    
        var url = $(this).attr('href'); 
    
        $.ajax({
            type: 'GET',
            url: url,
            dataType: 'html',
            cache: true,
            beforeSend: function() {
                $('#cboxLoadedContent').empty();
                $('#cboxLoadingGraphic').show();
            },
            complete: function() {
                $('#cboxLoadingGraphic').hide();
            },
            success: function(data) {                  
                $('#cboxLoadedContent').append(data);
            }
        });
    
    });
    

    0 讨论(0)
提交回复
热议问题