English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have a txt file that i can read using an onclick event, but it shows the text file all one one page in html, how can i get it to read each line?

text file:

name: karen | wendy
Age: 32 | 31

javascript:

function your_name()
{
var details = document.getElementById('details');
var url = "customers.txt";
ajax.open("GET", url);
ajax.onreadystatechange = function()
{
if (ajax.readyState == 200)
details.innerHTML =reply.responseText.split("\|");

}

works fine, but reads text file on one line? tried using \n and still wont work,

any ideas?

2007-12-02 08:15:28 · 3 answers · asked by Anonymous in Computers & Internet Programming & Design

3 answers

The contents of the file is being displayed as HTML and as you probably know whitespace is ignored in HTML.
To help it along you could simply change the line that does the displaying to instead of using

reply.responseText

use

reply.responseText.replace ( /\n/,"
")

This replaces all of the new lines in your input string into HTML break tags and should lay it out more as you wanted.

2007-12-02 21:08:38 · answer #1 · answered by nigel r 3 · 0 0

The file is not being put onto one line.
It is being put onto multiple lines.

The problem you are seeing is that the browser, when interpreting the HTML, is ignoring the whitespace of the file and placing the file onto one line.
If the file had

\n
at the end of each line then you would get the result that you are looking for.

2007-12-02 08:32:27 · answer #2 · answered by AnalProgrammer 7 · 0 0

you would have to do it all server side using like ASP and VB or use ASP.NET... you can do it with javascript but you will run into a problem with security issues on the users end also i don't think that the security of your website would allow you to open the file remotely.... in order for the javascript to read it the file has to be opened first and i don't think that it would allow an active x control to do this...

2016-05-27 06:57:28 · answer #3 · answered by ? 3 · 0 0

fedest.com, questions and answers