cloudpebble - Not receiving data from JSON source -


i'm attempting make pebble app reads data json url.

however, no matter can't seem make data appear on app.

when entering code in:

console.log(data.contents.availablebal); console.log(data.contents.currentbal); 

i expect result in logs get:

[phone] pebble-app.js:?: none [phone] pebble-app.js:?: none 

and when viewing app in emulator, both values data should be, "undefined".

my code follows. great!

var ui = require('ui'); var ajax = require('ajax');  var splashcard = new ui.card({   title: "please wait",   body: "downloading..." }); splashcard.show();  ajax(   {   url: 'https://djkhaled.xyz/balance.json',   type: 'json'   }, function(data) {   console.log(data.contents.availablebal);   console.log(data.contents.currentbal); var main = new ui.card({     title: 'balances',     body: 'available balance: ' + data.contents.availablebal + '\ncurrent balance: ' + data.contents.currentbal });   splashcard.hide();   main.show();   } ); 

this json,

{     "contents": [{         "availablebal": "$0.00 cr",         "currentbal": "$0.00 cr"     }] } 

you can not directly access data.contents.availablebal because availablebal not directly inside contents. contents has array , array's first object (object @ index 0) contains object has availablebal , currentbal keys.

i'm not javascript developer answer this,

var main = new ui.card({     title: 'balances',     body: 'available balance: ' + data.contents[0].availablebal + '\ncurrent balance: ' + data.contents[0].currentbal }); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -