how to display json data dynamically in my listview in intel xdk -
i developing hybrid application using intel xdk , jquery mobile framework ui. have json data, trying display json data in listview don't know how display json data in listview
this json data
{ "nl_wu":[ { "id":"42", "year":"2015", "month":"jan", "title":"newsletter", "file":"http://school.com/sample.pdf" }, { "id":"39", "year":"2015", "month":"jan", "title":"imagetest", "file":"http://school.com/sampleimage.jpg" } ] }
i trying above json data url using function
function showsmsmessage(){ var i; var out =""; var json; var arr ; var url ="http://example.com/filename.php"; var xhr = new xmlhttprequest(); xhr.open("get", "url", false); xhr.onload = function(){ if(xhr.status == 200) { var json_string = xhr.responsetext; json = eval ("(" + json_string + ")"); var s = json.stringify(json); arr = $.parsejson(s); for(i=0;i<arr.nl_wu.length;i++) { out = arr.nl_wu[i]; alert(out.title); } } else if(xhr.status == 404) { intel.xdk.notification.alert("web service doesn't exist", "error"); } else { intel.xdk.notification.alert("unknown error occured while connecting server", "error"); } } xhr.send(); }
i getting "title" json data using above javascript function, want display "title" in listview in intel xdk, please tell me how "title" in listview
as krisrak points out, there code answers question here:
https://stackoverflow.com/a/30239006/3476918
but should point out should not using eval purpose you're using it. it's simpler , safer use json.parse, i.e. instead of this:
var json_string = xhr.responsetext; json = eval ("(" + json_string + ")"); var s = json.stringify(json); arr = $.parsejson(s);
you should have this:
arr = json.parse(xhr.responsetext)
Comments
Post a Comment