dimsemenov / Magnific-Popup

Light and responsive lightbox script with focus on performance.
http://dimsemenov.com/plugins/magnific-popup/
MIT License
11.39k stars 3.48k forks source link

Loading images via Ajax #1121

Open jaimestuardo opened 5 years ago

jaimestuardo commented 5 years ago

Hello, I want just load a gallery of images from Ajax.

I tried this code:

        $('.popup-pic').magnificPopup({
                    type: 'ajax',
                    callbacks: {
                        parseAjax: function (mfpResponse) {
                            // mfpResponse.data is a "data" object from ajax "success" callback
                            // for simple HTML file, it will be just String
                            // You may modify it to change contents of the popup
                            // For example, to show just #some-element:
                            // mfpResponse.data = $(mfpResponse.data).find('#some-element');

                            // mfpResponse.data must be a String or a DOM (jQuery) element

                            console.log('Ajax content loaded:', mfpResponse);
                        },
                        ajaxContentAdded: function () {
                            // Ajax content is loaded and appended to DOM
                            console.log(this.content);
                        }
                    }
                });

And the URL is a URL that loads the list this way:

 items
         src: path1,
         src: path2,
         src: path3

That's all, but the only message I get is "TypeError: context is undefined".

Is the plugin prepared for this? if not, you could consider adding this in the future.

Thanks Jaime