javascript - Modernizr 和 ajax 加载冲突

标签 javascript jquery ajax modernizr

我有一个使用modernizr.js 的页面和一个自定义ajax 函数,该函数每x 秒重新加载页面内容。这是触发函数的代码。

function reloadSlides() {
    jQuery.ajax({
        url: document.location.href,
        cache: true,
        success: function(html){
            jQuery('#main').html(html);
        }
    });
}

当我查看 DOM 检查器时,这些类开始在 HTML 标记中一次又一次地重复,如下所示:

html lang="de" class=" js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions js no-touch cssanimations csstransitions" style=""

这是为什么呢?我怎样才能避免这种情况?

感谢您的浏览!

最佳答案

在我看来,您正在重新加载 ID 为 main 的元素内的整个页面。

jQuery('#main').html(html);

这将获取所有重新加载的 html 并将其填充到所选元素内。尝试仅重新加载 main 中的内容,而不是全部内容。

关于javascript - Modernizr 和 ajax 加载冲突,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20082804/

相关文章:

jquery - JQuery Lightbox 代码有问题

javascript - jquery 中的 radio 输入验证

jquery - 滚动到容器顶部后隐藏元素

javascript - 在 jQuery 中的最后一个元素之前追加元素不结束

javascript - 对象字面量 vs 构造函数+原型(prototype)

php - 分发时防止删除代码?

javascript - React JS setState 行为

javascript - 如何防止搜索引擎索引 ajax 生成的内容

javascript - 使用 AJAX 将图像上传到 ASP.NET Core 应用程序

javascript - jQuery 插件与小部件