Loading data in Javascript mode

edited July 2014 in JavaScript Mode

So I am converting my Java Applets to JavaScript. It is going OK, but I can't get my data to load in the JavaScript mode. The data is a matrix of strings and integers, /,/ delaminated, 170 columns and 600 rows. I have four files I need to load. The Java Applets work just fine.

I have tried avg = loadStrings("http://(URL)/OFFICIAL_gen_mw.txt");

I have also tried avg = loadStrings("OFFICIAL_gen_mw.txt"); with the txt file in the directory with the html

The rest of the code work with the loadStrings commented out. But with it is just locks up.

I think I am just missing a basic here, but can't find it in my Processing 2.0 book by Ira or the forum.

Thanks for your time, scen hjord

Answers

  • The data gets loaded in the draw {

    because I want to reload it every 10 minutes.

  • edited July 2014

    GoToLoop, here, your link isn't useful: it is just an outdated version of the Processing Reference page, even pointing to an article explaining how to sign a Java applet!

    Is there anything JS-specific to do to load a text file, like a directive to pre-load it, as we have to do for images?

    Note that basically, JS cannot load a file from an arbitrary URL (unless, perhaps, using some special protocol like JsonP), as it is restricted for security reasons. So the way to go is indeed to load from the same server than the JS / PDE file.

  • Thank you PhiLho. it is good to know that the URL route will not work. However, I still can't get the data to load from the local source. The text file is in my Processing script file, but it doesn't read. I notice that when you run, a new folder gets created called web-export. I tried putting the text file in there, but it overwrites each time you run. I tried export to the web and putting the text file in the web-export file and running the index.html, but that doesn't work either. I know people do this all the time, I am just missing something fundamental.

  • Answer ✓

    Try creating a folder called data inside the sketch folder and put the text files there then try again. No promises [-O<

  • See told you is was something simple and fundamental. Thanks quark, looks like it loaded.

  • edited August 2014

    When I publish to the web, do my data files also need to be in a data directory or the same directory as the index.html? do I need to list out the full address in the processing code? Everything works great in javascript mode and in Visual Studio. But once published, the web page acts like it can't find the data files.

  • in the same directory as the index.html. not all sites allow uploading files, even from the same directory. for example, I have switched to Altervista.org and I have activated the option

  • OK, thanks!

Sign In or Register to comment.