I tried to get information about the status of some of the buttons in JSON using the $. getJson ()
ID with a dash is broken into two parts, and they entered into an array regarr.
But I can not get data from JSON in this query:
data.regarr[0].regarr [1] //regarr is undefined
HTML:
<div class='buttons' id='lamps-fire1'>OFF</div>
My JSON:
{"lamps":{"fire1":"off","fire2":"off","fire3":"off"},"motor":"on","temperature":"12"}
JavaScript
$(document).ready(function()
{
function reloadvalues()
{
$('.buttons').each(function ()
{
var id=$(this).attr('id');
var re=/-/;
var re2=/[a-z0-9]{1,}[^-][a-z0-9]{1,}/ig;
var regarr=[];
regarr=id.match(re2);
if (id.search(re)==-1)
{
$.getJSON('homeapi.ini','tire=none&id='+encodeURIComponent(id),function (data)
{
if (data.motor=='off')
{
$(this).html('OFF.');
}
else{
$(this).html('ON.');
}
});
}
else{
$.getJSON('homeapi.ini','',function (data)
{
if ((regarr[1]!='undefined')||(regarr[0]!='undefined')||(regarr !='undefined'))
{
if (data.regarr[0].regarr[1]=='off')
{
$(this).html('OFF.');
}
else{
$(this).html('ON.');
}
}
});
}
});
}
setInterval(function (){
reloadvalues();
},5000);
});
Maybe someone knows what went wrong?