为什么在将 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 调用。#
我在页面底部发现了一些奇怪的东西 - 正在加载:
那是什么?不是我发的!
我使用 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/