我正在关注有关Javascript和Ajax的Lynda教程,并在主题为“使用同步XHR请求”的主题上挂起了这个问题。加载资源失败:服务器响应状态为404(未找到)
基本上HTML文件是:
JavaScript AJAX和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本地主机,并做检查元素我得到这个上面的错误说“无法加载资源:服务器用状态404(未回应找到)“
主线程上的同步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: "↵
↵404 Not Found↵↵Not Found
↵The requested URL /ajax/data.txt was not found on this server.
↵↵ Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80↵↵"
responseText: "↵
↵404 Not Found↵↵Not Found
↵The requested URL /ajax/data.txt was not found on this server.
↵↵ Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80↵↵"
responseType: ""
responseURL: "http://localhost/ajax/data.txt"
responseXML: null
status: 404
statusText: "Not Found"
timeout: 0
upload: XMLHttpRequestUpload
withCredentials: false
__proto__: XMLHttpRequest