/    Sign up×
Community /Pin to ProfileBookmark

Load Text file and display in table format.

I wish to display the output in a nice table format, the text file contains loads of rows and columns and each column separates either by space ” ” or “,” .
Please can someone help, at the moment it says, Problem retrieving data. Unknown

Further I am not sure if i need a webserver to make this work, as currenlty all html files are stored on a network drive and everything works fine except this section.

[code]
<html>
<head>
<script type=”text/javascript”>
var xmlhttp;
function loadXMLDoc(url)
{
xmlhttp=null;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=state_Change;
xmlhttp.open(“GET”,url,true);
xmlhttp.send(null);
}

function state_Change()
{
if (xmlhttp.readyState==4)
{// 4 = “loaded”
if (xmlhttp.status==200)
{// 200 = “OK”
document.getElementById(‘T1’).innerHTML=xmlhttp.responseText;
}
else
{
alert(“Problem retrieving data:” + xmlhttp.statusText);
}
}
}
</script>
</head>

<body onload=”loadXMLDoc(‘testdetails1.txt’)”>
<div id=”T1″ style=”border:1px solid black;width:300;padding:5″></div><br />
<button onclick=”loadXMLDoc(‘testdetails2.txt’)”>Click</button>
<button onclick=”loadXMLDoc(‘testdetails3.csv’)”>Click</button>

</body>
[/code]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@KorNov 05.2009 — as currenlty all html files are stored on a network drive[/QUOTE]
AJAX will work successfully only of the files are up [I]on a server[/I], not locally, neither on your computer (unless a server platform is installed on it - like Apache) nor on a network drive.
Copy linkTweet thisAlerts:
@salmansohailauthorNov 05.2009 — If we agree what you say, than how come the response of ajax falling under the loop and alert message is popping up:

if (xmlhttp.status==200)

{// 200 = "OK"

document.getElementById('T1').innerHTML=xmlhttp.responseText;

}

else

{

alert("Problem retrieving data:" + xmlhttp.statusText);

}

}
Copy linkTweet thisAlerts:
@KorNov 05.2009 — If we agree what you say, than how come the response of ajax falling under the loop and alert message is popping up:

if (xmlhttp.status==200)

{// 200 = "OK"

document.getElementById('T1').innerHTML=xmlhttp.responseText;

}

else

{

alert("Problem retrieving data:" + xmlhttp.statusText);

}

}[/QUOTE]


I bet the message tells you that the document's status is 4xx (error status), not 200.
Copy linkTweet thisAlerts:
@KorNov 05.2009 — Definition:

"[I]With AJAX, a JavaScript can communicate directly [COLOR=Blue]with the server[/COLOR], with the XMLHttpRequest object. With this object, a JavaScript can trade data [COLOR=Blue]with a web server,[/COLOR] without reloading the page.



AJAX uses asynchronous data transfer (HTTP requests) [COLOR=Blue]between the browser and the web server[/COLOR], allowing web pages to request small bits of information [COLOR=Blue]from the server[/COLOR] instead of whole pages.[/I]
"
×

Success!

Help @salmansohail spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...