我知道这个问题已经被问了很多次了,我已经经历了所有的解决方案,但无法解决问题。XMLHttpRequest无法加载
我是新手编程,并希望制作一个页面,通过Java脚本加载一个ID为“content”的div的内容。
这是我的索引页
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="jquery-3.1.1.js"></script>
</head>
<body>
<a href="#">home</a>
<a href="#">about</a>
<div id="content">
<script src="loader.js"></script>
</div>
</body>
</html>
,这是我loader.js
$(document).ready(function() {
$('#content').load('home.html');
});
当我运行的index.html我得到
jQuery的3.1.1。 js:9536 XMLHttpRequest无法加载file:/// C:/Users/Desktop/my_folder/home.html。
所有文件位于名为my_folder的文件夹中。
在jquery最新版本'.load()'方法已被弃用。 https://api.jquery.com/category/deprecated/ – Samir
@Samir:错误的方法。 .load将某些东西加载到标签中不会被弃用。这是已弃用的https://api.jquery.com/load-event/,而不是https://api.jquery.com/load/ – mplungjan
@mplungjan,在我提到的参考文献中,它提到' .load()方法已被弃用了吗? '.on(“load”)'是替换。请告诉我,如果我错了。 – Samir