json - Javascript extract data from Wikipedia API -


how extract title (list of metropolitan areas population) wikipedia api(http://en.wikipedia.org/w/api.php?format=json&action=query&titles=list_of_metropolitan_areas_by_population&prop=revisions&rvprop=content&callback=?)

i able data wikipedia having trouble extract data it.

function getjsonp(url, success) {      var ud = '_' + +new date,          script = document.createelement('script'),          head = document.getelementsbytagname('head')[0] || document.documentelement;        window[ud] = function(data) {          head.removechild(script);          success && success(data);      };        script.src = url.replace('callback=?', 'callback=' + ud);      head.appendchild(script);    }  getjsonp('http://en.wikipedia.org/w/api.php?format=json&action=query&titles=list_of_metropolitan_areas_by_population&prop=revisions&rvprop=content&callback=?', function(data){      console.log(data);      document.getelementbyid("output").innerhtml = data.query;  }); 
<div id="output">      want display article title here.  </div>

below shows in console. how can extract "from: "list_of_metropolitan_areas_by_population"" , display in front-end? enter image description here

you trying make content of html element javascript object, why saw result saw. want string, need access part of object give string.

document.getelementbyid("output").innerhtml = data.query.normalized[0].from; 

instead of

document.getelementbyid("output").innerhtml = data.query; 

here's link fiddle go along answer: http://jsfiddle.net/zsaj950t/


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -