0

I have a webpage on a raspberry pi. This page supports only HTML since I am using webIOpi. I can make use of python scripts and javascript.

When I link to this page hosted on the raspberry from outside I would need to pass some variables. but i do not want to put them in the URL as I would like to keep the URL clean. Is there any other method i can use to pass values to this page using any of the above resources?

sharkyenergy
  • 3,842
  • 10
  • 46
  • 97
  • some hacky things you can do ... none of which are gonna be pretty or very usefull ... (eg you could upload a json file then the js could read in the jsonfile) – Joran Beasley Feb 05 '14 at 18:21
  • Post wont work as its server side.. none of that data is actually sent to the user.. i could only use post if there is a way to read the post data with python when the page is generated.. – sharkyenergy Feb 05 '14 at 18:24
  • Hmm I guess I'm not understanding then - what exactly do you mean by `pass values to this page`? – admdrew Feb 05 '14 at 18:34
  • i have a webpage, online, with a Link to a local raspberry. i want to pass a few variables to the page (for example name=sharky) i could do it by usign the url, with the GET function, and read it out but i want to avoid that if possible. POST will not work because i can not read the POST data without the use of PHP. unless there is a way to read POST data using a python script. – sharkyenergy Feb 05 '14 at 18:39
  • 1
    "i can not read the POST data without the use of PHP" What? That's not true. – lanzz Feb 05 '14 at 18:40
  • How can i do it then? could you please post an example? – sharkyenergy Feb 05 '14 at 18:42
  • @lanzz have a look at this: http://stackoverflow.com/questions/1409013/how-to-read-the-post-request-parameters-using-javascript – sharkyenergy Feb 05 '14 at 19:13
  • @sharkyenergy `POST` and `GET` are simply two methods to transmit data to a web application. Anything that can handle `GET` should also be able to handle `POST` (including Python). Check [this out](http://webpython.codepoint.net/wsgi_request_parsing_post), or just Google `python read post`. – admdrew Feb 05 '14 at 20:20
  • @sharkyenergy Your link only references the fact that `POST` data can only be read server-side, so traditional JavaScript won't help. An answer there makes a cursory references to PHP, but that doesn't mean that PHP is *required*. – admdrew Feb 05 '14 at 20:23

1 Answers1

0

I don't know your markup, I got the same problem in a one-page-markup where content come and go (slide in and out) via javascript commands.
In my case I save some values in html attributes via javascript. This is a valid feature in HTML5, when you use a "data-" prefix for your value names (good explanation here) :

// Save it
element.setAttribute("data-foo", "bar");
// Get it
var foo = element.getAttribute("data-foo");

Note : reloading the page will unset the attributes ! ...but worked for me...

Michael P
  • 603
  • 1
  • 5
  • 22