can body help, m totally new in json want fetch image m bit confuse in array , object thing. or possible fetch image without img tag. thank in advance
this have tried:
function myfunction(worldpopulation) { var out = ""; var i; for(i = 0; i<worldpopulation.length; i++) out += '' + worldpopulation[i].rank; document.getelementbyid("id01").innerhtml = out; } just me fetch "rank" only
{ "worldpopulation": [ { "rank":1,"country":"china", "population":"1,354,040,000", "flag":"http://www.androidbegin.com/tutorial/flag/china.png" }, { "rank":2,"country":"india", "population":"1,210,193,422", "flag":"http://www.androidbegin.com/tutorial/flag/india.png" }, { "rank":3,"country":"united states", "population":"315,761,000", "flag":"http://www.androidbegin.com/tutorial/flag/unitedstates.png" }, ] }
the first thing content of json content page using xmlhttprequest
var request = new xmlhttprequest(); var url = "http://www.androidbegin.com/tutorial/jsonparsetutorial.txt"; request.onreadystatechange = function() { if(request.readystate == && request.status == 200) { var myarr = json.parse(xmlhttp.responsetext); myfunction(myarr); } } the implementation of myfunction
function myfunction(myarr) { for(var i=0; i< myarr.length; ++i) { var img ; // element want place img inside img.src = myarr[0].flag; } }
Comments
Post a Comment