Saurabh Sharma Saurabh Sharma - 4 months ago 15
Javascript Question

lnk with database with ajax in html

the code is showing this error ,dont know how to make it right "GET http://d/xampp/htdocs/cart/getuser.php net::ERR_NAME_NOT_RESOLVED showUser @showuser.php:27 onclick @showuser.php:9". even in my computer the location of file is "http://d/xampp/htdocs/cart/getuser.php" . i am using xampp



<html>
<head>
</head>
<body>


<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>

<script>
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;
}
}


}

</script>

</body>
</html>




Answer

Your URL is not valid.

http://D:/xampp/htdocs/cart/getuser.php

The D:/ is not valid. You can't use : in a URL. And you can't just directly reference a file on disk either - you reference a URL, which is not the same thing at all.

Does changing it to

http:/localhost/d/xampp/htdocs/cart/getuser.php

work? You've suggested something like this might be the right link. You need to check that your webserver is running and actually serving content at this link.