Dynamically add new HTML elements on page load after getting JSON data from Web API
Posted
by
Luis D Urraca
on Stack Overflow
See other posts from Stack Overflow
or by Luis D Urraca
Published on 2012-06-19T21:17:10Z
Indexed on
2012/06/20
3:16 UTC
Read the original article
Hit count: 316
I'm building an hybrid Android App using Phonegap/Apache Cordova. My app should get data from my web api. I'm using JSON to serve the data to the APP. So i got a the following code:
function init() {
document.addEventListener('deviceready', onDeviceReady, false);
var url = "http://23.21.128.153:3000/regions.json";var jsonresults;
$.getJSON(url,function(data){
jsonresults = data;
$.each(jsonresults, function(i,v){
$('#main-content').append('<li>'+jsonresults[i].name+'</li>');
});
});
}
and also on the body of the html i have a div called main-content. Everythings works fine in the Eclipse browser, but on the Android Emulator is not working. Not sure if there's another way to pull data from Web API using JSON and dinamically create HMTL elements after getting the data.
© Stack Overflow or respective owner