[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1354
  • Last Modified:

JavaScript to send URL + Text from a list (text file)

Simple concept (I hope).

I have a text file with one sentence per line. I need a a page with JS to be able to pull one line at a time (at defined intervals) and use the "GET" option to append that sentence onto a URL like such:

Everything from "" is always the same.
and so is "%3F&Submit=Send+Query&OriginatorAddress=8005551212" at the end.

So if my text file contains the following lines:

is john doe real
where is santa
who is jane doe?

The JS would send a GET request like this:

then x seconds later one like this

and then x seconds later

I hope this is clear enough ;)

Thanks in advance,

- dan -
  • 2
1 Solution
Are we to assume the text file resides on the client side? Or are you running this locally on the server? Or is the page suppose to retrieve the next line from a remote server?
If you are expecting the client javascript to be able to read the server text file, then this won't work.
If you have something like asp.net, or php, that can dynamically build the javascript (while reading the text file on the server), then that is possible.
Another possibility is to use Ajax to send a request to the server, with the line number of the file to be read, and when the response is received, have the page updated using this response.

Which of these interests you?
dansotoAuthor Commented:
Text file will be on the server.


If javascript can't handle it then php would be my next option.
That's what I figured.  You could use php to build the javascript in such a way as to have a array of strings to be used on the updates.  Since you are specifically speaking about GET requests, are these part of Ajax?

If you have an array of strings, for example, something like this:

<title>String Array</title>
<script type="text/javascript">

  var strings = [ 'is john doe real',
                  'where is santa',
                  'who is jane doe?'
  var index = 0;

  function doit() {
    if ( index < strings.length ) {
      alert( escape( strings[ index++ ] ) );
      setTimeout( "doit()", 5000 );
<body onload='setTimeout("doit()",5000)'>

If your php generated the string array, then the javascript could do the actual gets at the 5 second interval...

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now