[英]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.