[英]jQuery load() error : Synchronous XMLHttpRequest on the main thread is deprecated
I am trying to load a page within another page using jquery load() function. 我正在尝试使用jquery load()函数在另一个页面中加载页面。 Below is the code:
以下是代码:
... head code
</head>
<body id="body">
<div id="newbody"></div>
<button id="loadit">loadpage</button>
<script type="text/javascript">
$("#loadit").click(function(){
$( "#newbody" ).load( "edit.php?id=112" );
});
</script>
When I click the button the whole page is cleared and only a single bit of the "edit.php" page is displayed. 当我单击按钮时,整个页面被清除,只显示“edit.php”页面的一个位。 By single bit I mean that edit.php is supposed to display a prepopulated form and only a single field is displayed with no CSS whatsoever.
单个位我的意思是edit.php应该显示一个预先填充的表单,只显示一个没有CSS的单个字段。 Is it because I am using the wrong jQuery function ie load().
是因为我使用了错误的jQuery函数,即load()。 What I want to do is load a new page in a div tag within the current page.
我想要做的是在当前页面的div标签中加载新页面。
I also get the following warning in the console: 我还在控制台中收到以下警告:
jquery.min.js:4 Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience.
jquery.min.js:4主线程上的同步XMLHttpRequest因其对最终用户体验的不利影响而被弃用。
Where am I going wrong? 我哪里错了?
You may get this warning in case edit.php contains a script tag within it that loads an external javascript file eg 如果edit.php中包含一个加载外部javascript文件的脚本标记,则可能会收到此警告
<div>
SOME CONTENT HERE
</div>
<script src="/scripts/script.js"></script>
Just to note that this is from this stackoverflow answer - https://stackoverflow.com/a/28478146/3274227 请注意,这是来自这个stackoverflow的答案 - https://stackoverflow.com/a/28478146/3274227
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.