javascript - WordPress + jQuery Mobile - 主线程上的同步 XMLHttpRequest 已弃用?

标签 javascript php jquery wordpress jquery-mobile

为什么在将 jquery mobile 添加到我的 WordPress 网站后会出现以下这些错误?

Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.
send @ jquery.min.js?ver=3.1.1:4
ajax @ jquery.min.js?ver=3.1.1:4
a.ajax @ jquery-migrate.min.js?ver=3.0.0:2
r._evalUrl @ jquery.min.js?ver=3.1.1:4
Ia @ jquery.min.js?ver=3.1.1:3
append @ jquery.min.js?ver=3.1.1:3
r.fn.(anonymous function) @ jquery.min.js?ver=3.1.1:3
_include @ jquery.mobile.js:4790
(anonymous) @ jquery.mobile.js:890
(anonymous) @ jquery.mobile.js:4997
e @ jquery.min.js?ver=3.1.1:2
i @ jquery.min.js?ver=3.1.1:2
fireWith @ jquery.min.js?ver=3.1.1:2
A @ jquery.min.js?ver=3.1.1:4
(anonymous) @ jquery.min.js?ver=3.1.1:4

my-wordpress:1 IntersectionObserver.observe(target): target element is not a descendant of root.

WP 刚刚停止工作 - 当我单击菜单时,我可以看到 URL 已更改,但页面内容保持不变。

有什么想法吗?

这就是我在 function.php 中添加 jquery 内容的方法:

    // Load latest compiled and minified jquery.
    wp_enqueue_script( 'jquery-min', get_template_directory_uri() . '/node_modules/jquery/dist/jquery.min.js', array(), '3.1.1' );

    // Load latest compiled and minified jquery migrate.
    wp_enqueue_script( 'jquery-migrate-2', get_template_directory_uri() . '/node_modules/jquery-migrate/dist/jquery-migrate.min.js', array(), '3.0.0' );

    // Load latest compiled and minified jquery mobile.
    wp_enqueue_script( 'jquery-mobile', get_template_directory_uri() . '/node_modules/jquery-mobile/dist/jquery.mobile.min.js', array(), '1.4.1' );

注意:我的 WP 网站上没有任何 AJAX 调用。#

我在页面底部发现了一些奇怪的东西 - 正在加载:

enter image description here

那是什么?不是我发的!

我使用 jQuery mobile 因为我需要在移动设备上触摸和滑动图像:

// bind scroll to anchor links
// http://stackoverflow.com/questions/11397028/document-click-function-for-touch-device
$(document).on("click touchstart", "a[href^='#']", function (e) {
  var id = $(this).attr("href");
  if ($(id).length > 0) {
    e.preventDefault();

    // trigger scroll
    scrollMagicController.scrollTo(id);

      // if supported by the browser we can even update the URL.
    if (window.history && window.history.pushState) {
      history.pushState("", document.title, id);
    }
  }
});

// Add swipe to carousel.
$("#myCarousel").swiperight(function() {
  $(this).carousel('prev');
});
$("#myCarousel").swipeleft(function() {
  $(this).carousel('next');
});

最佳答案

我在将 jQuery Mobile 1.4.5 添加到 WordPress 管理区域时遇到了同样的问题。

可以通过更改 jQuery Mobile 文件中的以下代码行(jQM 版本 1.4.5 中的第 681-682 行)来修复该错误:

    // Automatically handle clicks and form submissions through Ajax, when same-domain
    ajaxEnabled: true,

    ajaxEnabled: false,

关于javascript - WordPress + jQuery Mobile - 主线程上的同步 XMLHttpRequest 已弃用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43135530/

相关文章:

javascript - 从 HTML 输入 onchange 属性调用 TypeScript 文件中定义的函数

java - 从 HTML 表中进行多重搜索

javascript - 根据视频源更改 div 的类

javascript - 默认返回背景颜色 - javascript bootstrap

jquery - 尝试使用 hasClass() 实现 if 语句,但它不起作用

javascript - 如何在两个 div 之间切换并在保存/刷新页面后保留在所选 div 上?

javascript - 将 javascript require 转换为 ES6 import

php - 使用 PHP 变量作为 MySQL 中的表名

php - Symfony 4 生产模式错误处理页面内存耗尽

php - 显示 'All Records' 选项