Hi . This is your response :
<html>
<head>
<title>Ajax at work</title>
<script language="javascript">
var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}
function getData(dataSource, divID)
{
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", dataSource);
XMLHttpRequestObject.onreadystatechange = function()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
</script>
</head>
<body>
<h1>Fetching data with Ajax & javaScript</h1>
<form>
<input type="button" value="Display Message">
onclick = "getData('data.txt', 'targetDiv')">
</input></form>
<div id="targetDiv">
<p>The fetched data will go here.</p>
</div>
</body>
</html>
Then create a data.txt near your html file.
Notice: If you work with windows you should run your project from IIS but if work with Linux or ubuntu you should run your project from terminal :
1-at terminal write "sudo nautilus".
2-then enter your password
3-then open a window and go to this address /var/www .
4-and copy your project in this file.
5-then open FireFox browser then enter this address in toolbar http://localhost
for example :http://localhost/XMLHttpRequest1/xmlhttprequest1.htm
now you can see your data .