问题
Here I am fetching the data from Wikipedia using following code. but it is not working for me.
var playListURL = 'http://en.wikipedia.org/w/api.php?format=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?';
$.getJSON(playListURL ,function(data) {
$.each(data.pages, function(i, item) {
alert(i);
});
});
DEMO LINK :- http://jsfiddle.net/rushijogle/dyeqy/
回答1:
Use the following code to get the data:
$.getJSON(playListURL ,function(data) {
$.each(data.query.pages, function(i, item) {
alert(item.title);
});
});
回答2:
Demo is at http://jsfiddle.net/dyeqy/3/
var playListURL = 'http://en.wikipedia.org/w/api.php?format=json&action=query&titles=India&prop=revisions&rvprop=content&callback=?';
$.getJSON(playListURL ,function(data) {
var hash = data
var page_value = ""
$.each(data["query"]["pages"],function(k,v){
alert(k)
$.each(v,function(key,val){
alert(key)
});
});
});
Like this you can take the revisions values also.
回答3:
It should be data.query.pages
instead of data.pages
Working Fiddle
来源:https://stackoverflow.com/questions/16735437/how-to-retrieve-data-from-wikipedia-api-using-json