Hi all, I’m working on the wiki viewer and have been stuck for a little while. Despite reading and searching for info, I still don’t fully understand how to get json info from the wikipedia api.
My function is below. Any pointers, tips or suggestions about where or what I might be doing wrong will be appreciated.
function search(){
var searchWord = $("#searchbox").val();
var apiResult = "https://www.mediawiki.org/w/api.php?action=query&format=json"
+ searchWord;
$.ajax({
url:apiResult,
dataType:"json",
success: function(info){
console.log(info)
}
//selector to display info to go here
}
Note the last property in the params object: origin: '*'. You need to specify origin with each request. This would seem to stop the whole project dead in its tracks, except you can specify origin: '*' which the API accepts as an anonymous request! begs the question: why even require it?!
Hi @belcurv,
Thanks for your reply. I’ve added everything to codepen here
With a little tweaking, I’m getting search results from the api, although I’m also getting an error message from the object. May have something to do with what you’ve mentioned above, but I have a headache now. lol