简体   繁体   English

jQuery加载正在触发主线程上的Synchronous XMLHttpRequest不建议警告

[英]jquery load is triggering Synchronous XMLHttpRequest on the main thread is deprecated warning

$('#in-view-contents').load("/browse/".concat(selectedId), function(responseData){
    var contentsLabelEl = document.getElementById("refined-contents-container");
    contentsLabelEl.style.display = "block";
    var arrayOfReloadScripts = ["/js/rateable.js", "/js/siteWide.js", "/js/search/searchEvents.js"];
    reloadScripts(arrayOfReloadScripts);
});

and reloadScripts just iterates though the array and calls this function: 和reloadScripts仅遍历数组并调用此函数:

function reload_js(src) {
    $('script[src="' + src + '"]').remove();
    $('<script>').attr('src', src).appendTo('head');
}

Does this cause jquery to make an synchronous call like explained in this SO answer? 这是否会导致jquery像 SO答案中所述进行同步调用? If not how do I rerun a set of functions that I need to run once the html/server response is loaded? 如果没有,当html / server响应加载后,如何重新运行我需要运行的一组函数?

EDIT: Here is the code for reloadScripts: 编辑:这是reloadScripts的代码:

var reloadScripts = function(array){
    var len = array.length;
    for (var i = 0; i < len; i++){
        reload_js(array[i]);
    }
}

I removed the jquery code in reload_js and changed it to the following: 我删除了reload_js中的jquery代码,并将其更改为以下内容:

function reload_js(src) {
    var originalScript = document.querySelector('script[src="' + src + '"]');
    var parentEl = originalScript.parentNode;
    parentEl.removeChild(originalScript);
    // $('script[src="' + src + '"]').remove();
    var newScript = document.createElement('script');
    newScript.src = src;
    parentEl.appendChild(newScript);
    // $('<script>').attr('src', src).appendTo('head');
}

I did this because in the comments it was mentioned that this might be a bug in jquery. 我这样做是因为在评论中提到这可能是jquery中的错误。 After doing this, the warning went away. 完成此操作后,警告消失了。

暂无
暂无

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

相关问题 jQuery load()错误:不推荐使用主线程上的同步XMLHttpRequest - jQuery load() error : Synchronous XMLHttpRequest on the main thread is deprecated 不赞成在主线程上使用同步XMLHttpRequest - Synchronous XMLHttpRequest on the main thread is deprecated 不推荐在主线程上使用同步XMLHttpRequest - Synchronous XMLHttpRequest on the main thread is deprecated WordPress + jQuery Mobile-不赞成在主线程上使用同步XMLHttpRequest吗? - WordPress + jQuery Mobile - Synchronous XMLHttpRequest on the main thread is deprecated? 使用jQuery加载外部javascript并禁止“不建议在主线程上使用同步XMLHttpRequest…” - Loading external javascript with jQuery and suppress “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 已被弃用,因为它会对最终用户的体验产生不利影响 - 警告 - Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience - warning XMLHTTPRequest错误:不建议在主线程上使用同步XMLHttpRequest…(SoundCloud API) - XMLHTTPRequest Error: Synchronous XMLHttpRequest on the main thread is deprecated … (SoundCloud API) 我在加载javascript时遇到问题。 错误:不建议使用[不推荐使用]主线程上的同步XMLHttpRequest - I have a problem whit load to javascript. Error: [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM