Hey, I need to reference some functions on the core by using javascript, and don’t know how to do so. I have been able do it through regular html, however i believe it is different. My code for the setup of the functions is below, as well as an example of the actual function. Could someone make an example of what the code should look like in javascript?
<div id='myDiv'> Response of the function will go here </div>
<script>
var accessToken = 1234;
var deviceID = 5678;
var baseURL = "https://api.particle.io/v1/devices/"+ deviceID + "/";
function callSpark(fName, args) {
var xmlhttp;
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
} else {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
}
var fullURL = baseURL + fName;
xmlhttp.open("POST", fullURL ,true);
xmlhttp.send("access_token="+ accessToken + "&args=" + args);
}
</script>
And then you would just call something like: callSpark(“motor1drive”, “command”) in javascript.
Please excuse any errors (this is handwritten, and mostly theory)
But since your access code is in there, I wouldn’t recommend making that page public.
I think @bko wrote a tutorial about using javascript to call a function on your spark…