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 -
Who is Participating?
HonorGodSoftware EngineerCommented:
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...
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?
HonorGodSoftware EngineerCommented:
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, 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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.