【问题标题】:Magnific Popup Ajax parse divMagnific Popup Ajax 解析 div
【发布时间】:2014-07-26 06:08:09
【问题描述】:

我试图从 magnific popup 的文档中实现如何从 ajax 调用 (http://dimsemenov.com/plugins/magnific-popup/documentation.html#ajax_type) 中仅检索特定的 div,但我的预期响应没有奏效。我发现,文档中有一个拼写错误: ParseAjax 和 AjaxContentAdded 都是用小写字母写的。在代码中,它是用大写驼峰写的。但这并没有解决我的问题。

 $('.JS_ajaxpopup').magnificPopup({
            type: 'ajax',
            ajax: {

                cursor: 'mfp-ajax-cur'
                tError: '<a href="%url%">The content</a> could not be loaded.'
            },
            callbacks: {
                ParseAjax: function(mfpResponse) {
                    console.log('test');
                    mfpResponse.data = $(mfpResponse.data).find('#mainContent');

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

甚至我的测试也没有出现在我的控制台中。也许有人暗示我为什么没有得到回应。弹出窗口已正确打开,但没有解析任何内容。我也试过这个:

 ParseAjax: function (mfpResponse) {

                    mfpResponse.data = "<div class='wrapping'>" + mfpResponse.data + "</div>";
                },
                AjaxContentAdded: function () {
                    this.content;
                }

不幸的是,什么也没发生。

【问题讨论】:

  • 您是否在&lt;a href="path-to-file.html" class="ajax-popup-link"&gt;Show inline popup&lt;/a&gt; 中设置了有效路径

标签: jquery ajax magnific-popup


【解决方案1】:

文档说明正确,回调名称应以小写字母开头(例如parseAjax)。

登录控制台您从$(mfpResponse.data).find('#mainContent') 获得的信息。如果#mainContent 是根元素,请使用filter 而不是find

【讨论】:

  • 遇到了问题,使用filter 解决了问题,因为#some-element 是root
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多