Processing POST using Forms
This link shows how a Form is setup in HTML using both the GET and POST methods. http://www.w3schools.com/tags/att_form_method.asp
The first line action refers to an ASP file on the server. The Posted data is processed by the ASP code.
form action="demo_form_method_post.asp" method="post">
For Espruino perhaps we can replace the ASP with a word that is used to steer the message to an appropriate handler.
One idea would be to use a Form to setup the column titles in a CSV file. It would create a CSV file on the SD card, taking the filename and column headers from the posted form. Ideas?
In previous forum posts we did the JSON POST from Java Script. http://forum.espruino.com/conversations/285131/
Set up an HTML file called Postform2.html and copy it to the SD card
I tried to list it here but it doesn't work in the preview. So I attached it.
Part of the server code with console.log(“Header “,req.headers) added.
var pdata="";
function serveHTML(){
var http=require("http").createServer(onPageRequest).listen(8080);
}//end serveFile
function onPageRequest(req, res) {
//console.log("Req= ",req);
console.log("Header",req.headers);
var a = url.parse(req.url, true);
console.log("URL ",a);
if (req.method=="POST") {
console.log("Post");
doPost(req,res);
}else{
doGet(req,res);
}//endif
}//end on PageRequest
The header and results of url.parse when Postform2.html is loaded and the Submit button is pressed.
It’s strange to see GET in the URL results. Suggestions?
The pdata is the message received after the header.
It would be prudent to add code to limit the number of characters we can receive so that memory isn’t exhausted. The server code as of now crashes when the Submit button is pressed.
Repeating with the JPpost9.HTML using the JSON post from a script. The LED1 button was clicked.
The header and results of url.parse
So the code needs to use req.method to determine GET or POST.
If it’s a POST, then use
var a = url.parse(req.url, true);
and a.”path”, or a.”pathname” to determine if it’s a “CMD” or a “LOGdata” POST.
Anyone have a guess which is the right one?
If it’s not what’s coded in the server, the reply header should be 404?
One issue is that when the Submit button is pressed a new tab in the browser is opened.
This is resolved by changing the target attribute in the HTML file. http://www.w3schools.com/tags/att_form_target.asp
form action="LOGdata" method="post" target="_blank">
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Processing POST using Forms
This link shows how a Form is setup in HTML using both the GET and POST methods.
http://www.w3schools.com/tags/att_form_method.asp
The first line action refers to an ASP file on the server. The Posted data is processed by the ASP code.
For Espruino perhaps we can replace the ASP with a word that is used to steer the message to an appropriate handler.
One idea would be to use a Form to setup the column titles in a CSV file. It would create a CSV file on the SD card, taking the filename and column headers from the posted form. Ideas?
In previous forum posts we did the JSON POST from Java Script.
http://forum.espruino.com/conversations/285131/
Set up an HTML file called Postform2.html and copy it to the SD card
I tried to list it here but it doesn't work in the preview. So I attached it.
Part of the server code with console.log(“Header “,req.headers) added.
The header and results of url.parse when Postform2.html is loaded and the Submit button is pressed.
It’s strange to see GET in the URL results. Suggestions?
The pdata is the message received after the header.
It would be prudent to add code to limit the number of characters we can receive so that memory isn’t exhausted. The server code as of now crashes when the Submit button is pressed.
Repeating with the JPpost9.HTML using the JSON post from a script. The LED1 button was clicked.
The header and results of url.parse
So the code needs to use req.method to determine GET or POST.
If it’s a POST, then use
var a = url.parse(req.url, true);
and a.”path”, or a.”pathname” to determine if it’s a “CMD” or a “LOGdata” POST.
Anyone have a guess which is the right one?
If it’s not what’s coded in the server, the reply header should be 404?
One issue is that when the Submit button is pressed a new tab in the browser is opened.
This is resolved by changing the target attribute in the HTML file.
http://www.w3schools.com/tags/att_form_target.asp
form action="LOGdata" method="post" target="_blank">
More to follow.
1 Attachment