Nope, that one actually does use the argument, which is the one in the line above:
requestURL = "https://api.particle.io/v1/devices/" + deviceID + "/" + varName + "/?access_token=" + accessToken;
How does the code you made display it to the HTML, and why would that be any different from my example? I made it output the data to the console since I didn’t feel like creating a bunch of extra HTML which you’d have to change anyhow.
JSON is just a way of formatting a string of data, nothing more, nothing less. It’s no black magic.
In fact, you’re also using JSON in your version by doing
document.getElementById("r2").innerHTML = json.result;
json object is the response from the variable request, and looks like this:
So that whole thing can be addressed as
json. If you want any of the
key:value pairs, you use the selector. Say you want the name, then you’d use
json.name, for the result you’d use
json.result, which is exactly what you did.
Now, compare that to my version, and spot the differences/similarities…
console.log('Function called succesfully:', data);