I am trying to test Ajax does this website support Ajax.
It should do!
Thank You for your reply. I am using the code below. It does not seem to change the text in data.txt.
Here is my code: Please let me know if you can help me.
<!DOCTYPE html>
<html>
<head>
<title>Ajax Lesson</title>
<script>
function getDataFromText(){
var xmlhttp;
if(window.XMLHtppRequest){
xmlhttp = new XMLHtppRequest();
}else{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState ==4 && xmlhttp.status==200){
document.getElementById('data').innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","data.txt",true);
xmlhttp.send();
}
</script>
</head>
<body>
<div id="data"><h2>Replace this text</h2></div>
<button type="button" onclick="getDataFromText()">Get Data</button>
</head>
</body>
</html>
Hi @pkn
Do you need to change the text of data.txt? or get data from it and print it?
Mention your website address too.
I think he wants to modify data in it.
Make sure you check your JavaScript console in your browser, and also your Network console. The JS console should have no errors, and the Network console will allow you to watch the request and response in real-time as your AJAX operation is made.
As @Supun says, if we can have a link, that will give us something to look at.
one minor typo;
Change XMLHtppRequest to XMLHttpRequest
if(window.XMLHttpRequest){
xmlhttp = new XMLHttpRequest();
Hi Supun,
Get data from the data.txt file and print it
Thank You for your help halfer
Thank You for your help Mortenrb, I will change that