我在网页中包含一个名为test.html的HTML页面。如下图所示:在HTML页面中使用jQuery包含HTML页面
<head>
<meta charset="utf-8">
<title>load demo</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<b>Content I want to Include is here: </b>
<div id="success"></div>
<script>
$("#success").load("test.html", function(response, status, xhr) {
if (status == "error") {
var msg = "Sorry but there was an error: ";
$("#success").html(msg + xhr.status + " " + xhr.statusText);
}
});
</script>
</body>
</html>
我得到一个错误阅读:
Sorry but there was an error: 0 NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file://machd/.../HTML/test.html'.
这个错误是什么意思?以及如何最好地解决它?
这是否[较早前的问题(http://stackoverflow.com/问题/ 28453213 /执行失败 - 发送xmlhttprequest)帮助? –
你需要一个服务器来使ajax工作。 尝试xampp或类似的解决方案,如果你还没有一个 – monxas
本地文件('file:// ...')往往不适用于xhr应用程序,请尝试本地开发服务器。 – swornabsent