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

emacadociousemacadocious Posts: 3Questions: 0Answers: 0
edited March 2012 in General
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?

Replies

  • allanallan Posts: 63,237Questions: 1Answers: 10,418 Site admin
    I'd suggest using Firebug / Webkit's Inspector to see if your code is triggering a JS error or not.

    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
This discussion has been closed.