Edje09
Edje09

Reputation: 29

Javascript arrays stored in server side files

I'm writing a bit of javascript for a web-based medical game (basically very new to javascript, but I have experience with Java, and I've just been picking things up as I go). The idea is that each case (patient) has several fields of data, and the names of the fields are always the same ("Heart Rate", "Chest X-Ray", etc), but the data associated with the names depend on the specific case. In just building the basic functionality, I've been using an associative array, so when someone enters an element (say, "Blood Test A"), the results appear in another area of the screen.

So, when I start creating cases, I'd like to have each case be a separate file on the server side which just stores the array so I can load the array at the beginning of the case and use the general references (which all the arrays have) to get the specific values stored in the specific array. I guess the other option would be to have a single file with multiple versions of the array and somehow pass the specific array back to the page's script and write it to a local variable.

Thoughts? Thanks!

Upvotes: 0

Views: 218

Answers (1)

Andrew Mao
Andrew Mao

Reputation: 36910

It sounds like you just want to store your arrays as JSON which you can directly load using the client, for example:

patientA.json:

{
    "Heart Rate": 160,
    "Chest xray": ... whatever
}

Put that file on your webserver, then your client can do (using jQuery, for example)

$.getJSON("server_addr/patientA.json", function (data) { // do something with data } );

Upvotes: 1

Related Questions