Author Topic: My AJAX simple code does not work  (Read 1658 times)

0 Members and 1 Guest are viewing this topic.

Offline Code.Illusionist

  • Royal Highness
  • ****
  • Posts: 687
  • Cookies: 39
  • Compile or die trying
    • View Profile
My AJAX simple code does not work
« on: June 07, 2015, 08:18:44 pm »
Greetings evilzone members.

I was following this basic tutorial from a pdf book I downloaded and so far I understood what they are saying but my code somehow does not work. Here is the whole code of my page:

Code: (javascript) [Select]
<!DOCTYPE html>
<html>
<head>

</head>
<body>
<form method="GET">
<input type="button" onclick="Validate('test.txt','demo')" value="Click me" />
</form>
<span id="demo">I will display message here!</span>
<script>
var XMLHttpRequestObject = false;

if(window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
}
function Validate(path,divID) {
if(XMLHttpRequestObject) {
var object = document.getElementById(divID);
XMLHttpRequestObject.open("GET",path);
XMLHttpRequestObject.onreadystatechange = function() {
if(XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
object.innerHTML = XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
} else {
document.getElementById(divID).innerHTML = "Sorry, but Ajax is not enabled for your browser";
}
}
</script>
</body>
</html>
« Last Edit: June 07, 2015, 08:19:00 pm by Code.Illusionist »
Vae Victis - suffering to the conquered

Offline Code.Illusionist

  • Royal Highness
  • ****
  • Posts: 687
  • Cookies: 39
  • Compile or die trying
    • View Profile
Re: My AJAX simple code does not work
« Reply #1 on: June 08, 2015, 06:45:04 am »
It is solved. Only problem was that I didn't put the file into WAMP www folder.
Vae Victis - suffering to the conquered