/    Sign up×
Community /Pin to ProfileBookmark

Loading text file from a URL?

I’ve been searching the web but couldn’t find a way to load a file located on a URL using javascript. Is it possible? in the case it’s possible, how can it be done?

Thanks for reading.

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@nathandelaneSep 26.2009 — The short answer to your question is, a resounding Yes! You would use the XMLHttpRequest object. Take a look at http://www.w3schools.com/Ajax/default.asp. If you need more help let us know.
Copy linkTweet thisAlerts:
@rnd_meSep 27.2009 — [CODE]
<html>
<script src="http://danml.com/mini">

var myPage=window.location.href;

alert( IO(myPage) );

</script>
</html>
[/CODE]
Copy linkTweet thisAlerts:
@drakkarauthorSep 27.2009 — Thanls for answering,

nathandelane: the thing is that I need to read unstructured plain text files. So I think AJAX is not for me.

rnd me: I think that code won't help me ?

Finally, I managed to read text files by using:

var input = new java.io.BufferedReader(
new java.io.InputStreamReader(
connect.getInputStream()));


The problem is that, although it allows me to read text files on my server, it fails on reading files on remote URLs.

Anyone knows why?
Copy linkTweet thisAlerts:
@criterion9Sep 27.2009 — The above is not Javascript but rather Java. Look up "http streams java" and you should find a tutorial or two to help you.
Copy linkTweet thisAlerts:
@nathandelaneSep 28.2009 — You don't have to use AJAX for structured content. It's a completely arbitrary method of getting content, and you can do whatever you want with it once you have it. AJAX doesn't limit you.
×

Success!

Help @drakkar 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

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