I've been tinkering with Z-Wave lately and I'm trying to make a page to include/exclude their products. But it's not going too well. I'm trying to check if a JSON key exists then display it on the page. I get
TypeError: data.controller is undefined
Here is the code:
window.setInterval(function(){
getData();
}, 2000);
function getData()
{
var milliseconds = (new Date).getTime();
var time = milliseconds.toString().substr(0, milliseconds.toString().length - 3) ;
$.postJSON( "http://192.168.1.102:8083/ZWaveAPI/Data/" + time, function( data ) {
if(data.controller.lastExcludedDevice.value) alert("EXCLUDED SOMETHING");
if(data.controller.lastIncludedDevice.value) alert("INCLUDED SOMETHING");
});
}
$.postJSON = function(url, data, callback, sync) {
// shift arguments if data argument was omited
if ( jQuery.isFunction( data ) ) {
sync = sync || callback;
callback = data;
data = {};
};
$.ajax({
type: 'POST',
url: url,
data: data,
dataType: 'json',
success: callback,
error: callback,
async: (sync!=true)
});
};
Json:
{
"controller.data.controllerState": {
"value": 0,
"type": "int",
"invalidateTime": 1424781697,
"updateTime": 1425338938
},
"controller.data.lastIncludedDevice": {
"value": 42,
"type": "int",
"invalidateTime": 1424781697,
"updateTime": 1425338938
},
......
Any help is greatly appreciated.