无法加载资源:服务器响应状态 404(未找到)
Failed to load resource: the server responded with a status 404(not found)
我正在关注 Javascript 和 Ajax 上的 Lynda 教程,并挂断了关于主题 "Using Synchronous XHR request" 的这个问题。
基本上 html 文件是:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JavaScript AJAX</title>
</head>
<body>
<script src = "script.js"></script>
</body>
</html>
并且 javascript 文件是:
var request = new XMLHttpRequest();
request.open('GET', 'data.txt', false);
request.send();
console.log(request);
data.txt 文件上有 "Hello World"。
项目文件的路径是
C:/wamp/www/ajax/index.html
C:/wamp/www/ajax/script.js
当我在 wampserver 上打开本地主机并检查元素时,我得到上面的错误提示 "Failed to load resource: the server responded with a status 404(not found)"
主线程上的同步 XMLHttpRequest 已弃用,因为它会对最终用户的体验产生不利影响。如需更多帮助,请查看 http://xhr.spec.whatwg.org/。
http://localhost/ajax/script.js 加载资源失败:服务器响应状态为 404(未找到)
XMLHttpRequest
onabort: null
onerror: null
onload: null
onloadend: null
onloadstart: null
onprogress: null
onreadystatechange: null
ontimeout: null
readyState: 4
response: "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">↵<html><head>↵<title>404 Not Found</title>↵</head><body>↵<h1>Not Found</h1>↵<p>The requested URL /ajax/data.txt was not found on this server.</p>↵<hr>↵<address>Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80</address>↵</body></html>↵"
responseText: "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">↵<html><head>↵<title>404 Not Found</title>↵</head><body>↵<h1>Not Found</h1>↵<p>The requested URL /ajax/data.txt was not found on this server.</p>↵<hr>↵<address>Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80</address>↵</body></html>↵"
responseType: ""
responseURL: "http://localhost/ajax/data.txt"
responseXML: null
status: 404
statusText: "Not Found"
timeout: 0
upload: XMLHttpRequestUpload
withCredentials: false
__proto__: XMLHttpRequest
hungup with this problem on topic "Using Synchronous XHR request".
所以不要那样做。
request.open('GET', 'data.txt', false);
false
表示"Don't make an asynchronous request"。把它拿出来。
request.open('GET', 'data.txt');
然后您需要使用事件侦听器,而不是期望浏览器在继续执行 JavaScript.
之前等到响应返回
request.addEventListener("load", function (event) {
console.log(this);
});
当然,这与以下无关:
Failed to load resource: the server responded with a status of 404 (Not Found)
这只是意味着 http://localhost
说 /ajax/data.txt
不存在。
我正在关注 Javascript 和 Ajax 上的 Lynda 教程,并挂断了关于主题 "Using Synchronous XHR request" 的这个问题。
基本上 html 文件是:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JavaScript AJAX</title>
</head>
<body>
<script src = "script.js"></script>
</body>
</html>
并且 javascript 文件是:
var request = new XMLHttpRequest();
request.open('GET', 'data.txt', false);
request.send();
console.log(request);
data.txt 文件上有 "Hello World"。
项目文件的路径是
C:/wamp/www/ajax/index.html
C:/wamp/www/ajax/script.js
当我在 wampserver 上打开本地主机并检查元素时,我得到上面的错误提示 "Failed to load resource: the server responded with a status 404(not found)"
主线程上的同步 XMLHttpRequest 已弃用,因为它会对最终用户的体验产生不利影响。如需更多帮助,请查看 http://xhr.spec.whatwg.org/。 http://localhost/ajax/script.js 加载资源失败:服务器响应状态为 404(未找到)
XMLHttpRequest
onabort: null
onerror: null
onload: null
onloadend: null
onloadstart: null
onprogress: null
onreadystatechange: null
ontimeout: null
readyState: 4
response: "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">↵<html><head>↵<title>404 Not Found</title>↵</head><body>↵<h1>Not Found</h1>↵<p>The requested URL /ajax/data.txt was not found on this server.</p>↵<hr>↵<address>Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80</address>↵</body></html>↵"
responseText: "<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">↵<html><head>↵<title>404 Not Found</title>↵</head><body>↵<h1>Not Found</h1>↵<p>The requested URL /ajax/data.txt was not found on this server.</p>↵<hr>↵<address>Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80</address>↵</body></html>↵"
responseType: ""
responseURL: "http://localhost/ajax/data.txt"
responseXML: null
status: 404
statusText: "Not Found"
timeout: 0
upload: XMLHttpRequestUpload
withCredentials: false
__proto__: XMLHttpRequest
hungup with this problem on topic "Using Synchronous XHR request".
所以不要那样做。
request.open('GET', 'data.txt', false);
false
表示"Don't make an asynchronous request"。把它拿出来。
request.open('GET', 'data.txt');
然后您需要使用事件侦听器,而不是期望浏览器在继续执行 JavaScript.
之前等到响应返回request.addEventListener("load", function (event) {
console.log(this);
});
当然,这与以下无关:
Failed to load resource: the server responded with a status of 404 (Not Found)
这只是意味着 http://localhost
说 /ajax/data.txt
不存在。