简体   繁体   English

WordPress + jQuery Mobile-不赞成在主线程上使用同步XMLHttpRequest吗?

[英]WordPress + jQuery Mobile - Synchronous XMLHttpRequest on the main thread is deprecated?

Why do I get these errors below after adding jquery mobile to my WordPress website? 将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.

The WP just stopped working - when I click to the menu and I can see that URL has changed but the page content stay the same. WP刚刚停止工作-当我单击菜单时,我可以看到URL已更改,但页面内容保持不变。

Any ideas? 有任何想法吗?

This is how I add the jquery stuff in the function.php: 这就是我在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' );

Notes: I don't have any AJAX call on my WP site.# 注意:我的WP网站上没有任何AJAX呼叫。#

I found something odd at the bottom of my page - Loading: 我在页面底部发现了一些奇怪的东西-正在加载:

在此处输入图片说明

What's that? 那是什么? Is not from me! 不是我的!

I use jQuery mobile because I need to touch and swipe images on mobile devices: 我使用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');
});

I ran in the same issue with adding jQuery Mobile 1.4.5 to the wordpress admin area. 我在将jQuery Mobile 1.4.5添加到wordpress管理区域时遇到了同样的问题。

The error can by fixed by changing the following lines of code in your jQuery Mobile file (lines 681-682 in jQM Version 1.4.5): 可以通过更改jQuery Mobile文件中的以下代码行(jQM版本1.4.5中的681-682行)来修复错误:

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

to

    ajaxEnabled: false,

Just to add to Examizer's answer, if you prefer not to amend the jQueryMobile code directly you can run your own custom script to set defaults on jQueryMobile. 仅添加到Examizer的答案中,如果您不想直接修改jQueryMobile代码,则可以运行自己的自定义脚本以在jQueryMobile上设置默认值。 Just make sure you queue it before jQueryMobile's script is queued. 只要确保 jQueryMobile的脚本排队之前将其排队即可。

This worked for me: 这为我工作:

$(document).bind("mobileinit", function () {
    $.mobile.ajaxEnabled = false;
});

From this answer: https://stackoverflow.com/a/8684532 从这个答案: https//stackoverflow.com/a/8684532

The main thread is used for UI rendering. 主线程用于UI渲染。 Here you're trying to make synchronous requests on this same thread, which would result in screen freezes while you waiting for the HttpResponse. 在这里,您尝试在同一线程上发出同步请求,这将导致在等待HttpResponse时屏幕冻结。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 不赞成在主线程上使用同步XMLHttpRequest - Synchronous XMLHttpRequest on the main thread is deprecated 不推荐在主线程上使用同步XMLHttpRequest - Synchronous XMLHttpRequest on the main thread is deprecated jQuery加载正在触发主线程上的Synchronous XMLHttpRequest不建议警告 - jquery load is triggering Synchronous XMLHttpRequest on the main thread is deprecated warning 使用jQuery加载外部javascript并禁止“不建议在主线程上使用同步XMLHttpRequest…” - Loading external javascript with jQuery and suppress “Synchronous XMLHttpRequest on the main thread is deprecated…” jQuery load()错误:不推荐使用主线程上的同步XMLHttpRequest - jQuery load() error : Synchronous XMLHttpRequest on the main thread is deprecated 不推荐使用主线程上的Firebase同步XMLHttpRequest - Firebase Synchronous XMLHttpRequest on the main thread is deprecated $.get 不是 function,不推荐使用主线程上的同步 XMLHttpRequest - $.get is not a function, Synchronous XMLHttpRequest on the main thread is deprecated XMLHTTPRequest错误:不建议在主线程上使用同步XMLHttpRequest…(SoundCloud API) - XMLHTTPRequest Error: Synchronous XMLHttpRequest on the main thread is deprecated … (SoundCloud API) Angular指令获取“主线程上的同步XMLHttpRequest已弃用” - Angular directive gets “Synchronous XMLHttpRequest on the main thread is deprecated” 滚动事件不起作用:主线程上的同步 XMLHttpRequest 已弃用 - Scroll Event Not Working: Synchronous XMLHttpRequest on the main thread is deprecated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM