I have been playing with the Web_AjaxRGB.ino example. I understand that it uses:
$.post(’/rgb’, { red: ui.value });
to send the red value from the web page to the Photon.
What I would like to know is what if I wanted to get a value from the Photon and put it on website.
might anyone be able to shed some light on this?
I used this example before with another device, but I cant seem to figure out how in the .ino example to send the data back. Below is my index.html file if it helps.
<!DOCTYPE html>
<html lang='en'>
<head>
<title>IR Temp</title>
<meta charset='utf-8'>
<meta name='viewport' content='width=device-width, initial-scale=1' />
<link href='https://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css' rel='stylesheet'>
</head>
<body onload='grabData();'>
<div class='container'>
<div class='jumbotron'>
<div class='text-center'>
<div class='panel panel-primary'>
<h1 style='display: inline'>Temperature: <span id='new_val'> </span></h1>
</div>
</div>
</div>
<!-- javascript -->
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.0.3/jquery.min.js'></script>
<script src='https://netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js'></script>
<script>
function grabData() {
$.post(document.URL, {
gd: 'get_temp'
}, function(data) {
$('#new_val').html(data.AV);
}, 'json')
.always(function() {
setTimeout(grabData, 2000);
}) // polls every 2 secs
.fail(function(data) {
alert('ERROR: ' + data.responseText);
});
}
</script>
</body>
</html>