I am trying to make a JSON request using jquery, the first JSON request return me the data I want.
After the first Success JSON request, I want to look at the results from the first JSON request and use it in my second JSON request.
The problem I am facing currently, is my second JSON request return empty object. Can someone help me figure out why my second JSON return nothing?
Even though when i post the second JSON url on a website url, it show me the JSON data. but in my program it is not returning anything.
Here is the code
$(document).ready(function() {
var api_wiki = "https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=cat&srwhat=text&callback=?";
var api_wiki_extract = "https://en.wikipedia.org/w/api.php?action=query&format=json&prop=info%7Cextracts&inprop=url&exsentences=1&callback=?&titles=";
var sp;
var linkReady = [];
var linkR;
$.getJSON(api_wiki, function(data) {
sp = data.query.search;
linkR = workWithTheData(sp);
anotherJSON(linkR);
}); //End of getJSON 1
function workWithTheData(sp) {
for (var i = 0; i < sp.length; i++) {
linkReady[i] = api_wiki_extract + sp[i].title;
}
return linkReady;
}
function anotherJSON(linkR){
$.getJSON(linkR[0], function(data1) {
console.log(data1);
});
}
}); //End of document ready