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

x
  • 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:

http://255.255.255.255/?Data=is+%22john+doe%22+real%3F&Submit=Send+Query&OriginatorAddress=8005551212

Everything from "http://255.255.255.255/?Data=" 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:

http://255.255.255.255/?Data=is+%22john+doe%22+real%3F&Submit=Send+Query&OriginatorAddress=8005551212

then x seconds later one like this

http://255.255.255.255/?Data=where+%22is+doe%22+santa%3F&Submit=Send+Query&OriginatorAddress=8005551212

and then x seconds later

http://255.255.255.255/?Data=who+%22is+jane+%22doel%3F&Submit=Send+Query&OriginatorAddress=8005551212

I hope this is clear enough ;)

Thanks in advance,

- dan -
0
dansoto
Asked:
dansoto
  • 2
1 Solution
 
L00MCommented:
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?
0
 
HonorGodCommented:
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?
0
 
dansotoAuthor Commented:
L00M:
Text file will be on the server.

HonorGod:

If javascript can't handle it then php would be my next option.
0
 
HonorGodCommented:
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:

<html>
<head>
<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 );
    }
  }
</script>
</head>
<body onload='setTimeout("doit()",5000)'>
</body>
</html>

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

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