You are reading a single comment by @ClearMemory041063 and its replies. Click here to read the full conversation.
  • 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 
    

    Additional info can be had here:
    Add Event Listener

About