/    Sign up×
Community /Pin to ProfileBookmark

read a txt file

Hi everyone,

I would like to know if is possible in javascript or Vbscript read (only read) a simple .txt file who is located on server.

If it’s possible how can I do?

This is my piece of code in vbscript that read a local .txt file

dim fso, ts, retstring, Mostra
Const forReading = 1
Set fso = CreateObject(“Scripting.FileSystemObject”)
Set ts = fso.OpenTextFile (“E:/PROGETTO/XML/storico.txt”, ForReading)

What type of modified can I do to this?

Thanks in advance.

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@David_HarrisonApr 30.2004 — Client side VBScript is IE only, use JavaScript instead. I assume you want this to run on the client and not the server otherwise you would have posted in the ASP forum.

JavaScript can read .js files and code from the file can be executed as well.

You can reference .js files like this:

<script type="text/javascript" src="file.js"></script>

Generally these .js file are referenced in the head section but there's nothing to stop you from putting them elsewhere in your code.
Copy linkTweet thisAlerts:
@VladdyApr 30.2004 — Only the same domain:
<i>
</i>function getFile(filename)
{ oxmlhttp = null;
try
{ oxmlhttp = new XMLHttpRequest();
oxmlhttp.overrideMimeType("text/xml");
}
catch(e)
{ try
{ oxmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{ return null;
}
}
if(!oxmlhttp) return null;
try
{ oxmlhttp.open("GET",filename,false);
oxmlhttp.send(null);
}
catch(e)
{ return null;
}
return oxmlhttp.responseText;
}
Copy linkTweet thisAlerts:
@TheBearMayApr 30.2004 — Vladdy - pretty slick?
Copy linkTweet thisAlerts:
@magliestauthorMay 03.2004 — Thank you very much

It work very very well!

bye.
Copy linkTweet thisAlerts:
@IceMetalPunkMay 14.2004 — I was browsing the forums and I realized that this code could help me w/ something else, but I have one quick question: would it work with NS 4.0? Thanks...

-IceMetalPunk

P.S. I hope you don't mind me posting this in your topic, magliest... ?
Copy linkTweet thisAlerts:
@VladdyMay 14.2004 — Nope.

Let NN4.* fall back on no-JS functionality.
×

Success!

Help @magliest 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...