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
![emacadocious](https://secure.gravatar.com/avatar/ac35c04f9eeeda3b6e66235ab6c692c6/?default=https%3A%2F%2Fvanillicon.com%2Fac35c04f9eeeda3b6e66235ab6c692c6_200.png&rating=g&size=120)
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