http form to get data #5934
Replies: 1 comment
-
Posted at 2017-11-13 by @allObjects Take a look at @ClearMemory041063's post: For very simple forms you can - client-side - on 'post' grab the data from the form fields and add it as url parms to a get url and do a get and then use - server-side - url.parse... Posted at 2017-11-13 by Planer do you have simple code how it do? (input text field with button "send" on web server, and put data on JS code after click button) Posted at 2017-11-14 by ClearMemory041063 Here is a snippet of code from the script section of an HTML document. A button press event triggers the JSONpost function. I think there is a way to insert the message length as well, but that work is currently archived.
Additional info can be had here: Posted at 2017-11-14 by ClearMemory041063 Look at the attached HTML files in the link @allObjects supplied above. Posted at 2017-11-14 by Planer thanks! Posted at 2017-11-14 by @allObjects In extra post I will provide you with code from an active robot I made for my wife as stage partner for a kid summer camp themed 'Maker Fair'. The idea was to use recycled stuff... so some of my hunted and gathered items (and hoarded for decades -literally) re-found their destiny and purpose... The robot was blinking/flahing/steady lighting its eyes, rotating its antenna slow, medium, and fast (at one point it was also turning its head). Other options are left for the next opportunity, like driving around on his swivel wheels, moving its arms, and sensing and talking.... In the picture the - just taped on - electronics have been removed (shown in separate shot, also attached). The attached clip robotAction.mp4 shows some action... A Espruino-Wifi was all in one: independent Wifiu Access Point, Web Server, and Robot controller. Any Wifi device / phone can drive it through browser Web page interface. For driving/flashing the heavy LED lights for the eyes I used @drazzy 's MOSFETs from Tindies, for the Antenna (and Head Turning) I used some cheap, geared steppers. The Head Truning was done with 3 wheels running around, one driven (as shown with the 3d printed wheel... unfortunately, it had not enough grip and one driving stepper was not reliably turning / sufficient). As power supply I used these battery banks you get cheap. They can easily push some real Amps... The controlling Web page was just buttons with some javascript on click. Attachments: Posted at 2017-11-14 by @allObjects Here the complete code:
The page has an iFrame which was used as the communication vehicle (sending a get with parms in line 9 by setting the iFrame's source (url) and url.parse in lines 61..71) so that not the whole page has to be loaded again, and also use a simpler approach than XHTMLRequest / POST / body work... It was all put together in a few hours on Sun afternoon... Posted at 2017-11-14 by Planer thanks for all!) Posted at 2017-11-14 by Planer i developed most brut variant, but it working)))
var b consist all your data) Posted at 2017-11-14 by Planer ...and also more correct variant
var b consist all your data, but data requires parse. (example data: "fname=Pavel&lname=123&xname=rtavel&zname=12673") for do this i developed little parser:
or more simple variant parser:
Posted at 2017-11-15 by @allObjects In code in post #10
I would change the sequence to do the request processing first (lines 2 and 5), and then the response (lines 3 and 4):
On a side note: Using single quote (') instead of double quotes (") for coding html fragments as literal Strings makes life much easier (and code much more legible): you do not need to escape the double quotes ("). Furthermore, you do not need the carriage returns and line feeds / new lines (/r, /n) in html source. This helps you preserve memory of which you are usually anyway in short supply... last but not least, mutli-line literal strings that recently became available helps even more with legibility: ;)
In 1st code in post #11: For some GET/POST discussion, take a look at [Testing SW from Espruino book, ....code from page 246 (Espruino Pico+ESP8266)] (http://forum.espruino.com/conversations/311282/). Posted at 2017-12-04 by @gfwilliams For anyone else who gets here, there's now a tutorial on HTTP POST and Forms: http://www.espruino.com/Posting+Forms |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-11-13 by Planer
Hello, i am newbie in html. How i can get data from my http webserver from input text field to variable in code or console.log()? I am trying, but nothing didn't work. ver 1.91 esp8266
Beta Was this translation helpful? Give feedback.
All reactions