unobtrusive JavaScript method that gets data from txt file and writes to element in HTML
unobtrusive JavaScript method that gets data from txt file and writes to element in HTML

I am pretty new to programming, and am still learning the ropes. For a homework assignment I have to create an unobtrusive JavaScript method that gets data from a provided text file (ajaxData.txt) and writes it to an element in a html file. I got most of my code through forums and w3schools and when I click the button nothing is happening. Can someone please help me?? And to make things more interesting I am NOT allowed to use a JavaScript library...Here is my code:
function loadXMLDoc(url)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('A2').innerHTML=xmlhttp.statusText;
}
}
xmlhttp.open("GET","ajaxData.txt",true);
xmlhttp.send();
}
Retrieve data from XML file
Status text:
Get XML data
Any ideas?
function loadXMLDoc(url)
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById('A2').innerHTML=xmlhttp.statusText;
}
}
xmlhttp.open("GET","ajaxData.txt",true);
xmlhttp.send();
}
Retrieve data from XML file
Status text:
Get XML data
Any ideas?
This discussion has been closed.
Replies
However, this forum is for DataTables related questions, and since you can't use a library, I'm afraid we can't really help you here :-)
Allan