Getting data from a remote server

This turns out to be pretty easy.

First, you’ll need to reformat the data on the server a bit and rename
the file:

Contents of the file:


Call it whatever you like – in my sample, it’s data.js.

Here’s the code in an NS Basic/App Studio program:

'GetData - gets some data from a remote site and processes it

Function Button1_onclick()
  head = document.getElementsByTagName("head")[0]
  newScript = document.createElement("script")
  newScript.type = "text/javascript"
  newScript.src = ""
End Function

Function processData(s)
  For i=0 To UBound(data)-1
    Textarea1.value=Textarea1.value & data(i) & vbcrlf
  End If
End Function

The data in data.js is actually a mini program: it calls a function called processData with the data you want to download.

In the above code, Button1_onclick() takes that file, inserts it into your program and executes it. The code in the file calls processData, which interprets the incoming data and, in this case, simply displays it.

You’ll have to take care that no one can modify data.js, or they could
have all kinds of fun!

This sample will be included in the next build.