代码显示此错误,不知道如何正确
"获取 http://d/xampp/htdocs/cart/getuser.php 网::ERR_NAME_NOT_RESOLVED显示用户@showuser.php:27点击@showuser.php:9"。
即使在我的电脑中文件的位置是"http://d/xampp/htdocs/cart/getuser.php"。我正在使用 xampp
function showUser() {
httpRequest = new XMLHttpRequest();
if (!httpRequest) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}
httpRequest.onreadystatechange = alertContents;
httpRequest.open("GET", "http://D:/xampp/htdocs/cart/getuser.php", true);
httpRequest.send();
}
function alertContents() {
if (httpRequest.readyState === XMLHttpRequest.DONE) {
if (httpRequest.status === 200) {
document.getElementById("txtHint").innerHTML = xmlhttp.responseText;
}
}
}
<form>
enter digit : <input type='text' id='id' /> <br />
<input type='button' onclick='showUser(this.value)' value='select' />
</form>
<br>
<div id="txtHint"><b>Person info will be listed here...</b></div>
您的网址无效。
http://D:/xampp/htdocs/cart/getuser.php
D:/无效。不能在 URL 中使用 :。而且您也不能直接引用磁盘上的文件 - 您引用一个URL,这根本不是一回事。
是否将其更改为
http:/localhost/d/xampp/htdocs/cart/getuser.php
工作?您建议这样的东西可能是正确的链接。您需要检查您的网络服务器是否正在运行并实际在此链接中提供内容。