postUpdate() changes the LED's brightness by performing an HTTP POST to the server. This time, it's the LEDControl.post() method in our API server that handled the request:
// POST Request to server to set LED state.
function postUpdate(payload) { // (4)
$.post("/led", payload, function(serverResponse, status) {
console.log(serverResponse)
updateControls(serverResponse); // (5)
});
}
On line (4), it receives and parses (remember arg_parser from LEDControl) the data in the payload parameter. payload is a JavaScript object with a state child property. We'll see this object constructed later in the web page slider's change event handler.
For consistency, we also update the controls on line (5) even though, in our case, the serverResponse variable will contain the same level value as the payload parameter...