Here is a snippet of code from the script section of an HTML document. A button press event triggers the JSONpost function.
As written it sends an 'A'. The Espruino code sees the 'A' and sends some data back in S.
I think there is a way to insert the message length as well, but that work is currently archived.
function JSONpost(){
//code to post the Postobj to the server and get a reply
var yhttp = new XMLHttpRequest();
yhttp.addEventListener("error",JSONpost1);
yhttp.open("POST","CMD", true);
yhttp.send("A"); // text to send
yhttp.onreadystatechange = function() {
if (yhttp.readyState == 4 && yhttp.status == 200) {
var S=JSON.parse(yhttp.responseText);
// the reply is in S
}//endif
};//end onreadystate function
}//end JSONpost
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.
Here is a snippet of code from the script section of an HTML document. A button press event triggers the JSONpost function.
As written it sends an 'A'. The Espruino code sees the 'A' and sends some data back in S.
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:
Add Event Listener