O'Reilly logo

Mastering Internet of Things by Peter Waher

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Calling our actuator API from JavaScript

Calling the actuator API is done slightly differently, since we use the POST method instead of the GET method. We need to send some content with the request. Sending text-based content is easy. We only need to send a string in the send() method. But we still need to set the Content-Type header to describe what type of text-based content we want to send. In our example, we use plain text:

var Span = document.getElementById("OutputState"); var CurrentState = Span.innerHTML; var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function () { if (xhttp.readyState == 4) { if (xhttp.status == 200) { var Data = JSON.parse(xhttp.responseText); Span.innerHTML = Data.output ? "ON" : "OFF"; } delete xhttp; ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required