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

Posted on 2007-08-10
Last Modified: 2013-11-05
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 -
Question by:dansoto
    LVL 11

    Expert Comment

    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?
    LVL 41

    Expert Comment

    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?
    LVL 7

    Author Comment

    Text file will be on the server.


    If javascript can't handle it then php would be my next option.
    LVL 41

    Accepted Solution

    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

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now