wisekodama sends brownie points to @skycoder01 :sparkles: :thumbsup: :sparkles:
Guys, I'm getting desperate. I'm just about ready to give up on this stupid Wikipedia Viewer. I'm so frustrated. I can't see what I'm doing wrong.
I decided to set up a separate CodePen just to work on the $.getJSON();
call to the API. Here's my script:
$(document).ready(function() {
$("#button").click(function() {
$("#greeting").html("Hello World");
$.getJSON("https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=json", function(json) {
$("#output").html(JSON.stringify(json));
});
});
});
I've just stuck the 'Hello World' in so I can check the event handler is working, which it is. The URL I'm using is lifted directly from the Wikipedia API documentation, and works perfectly when pasted into my browser. The 'stringify' bit is copied directly from the FreeCodeCamp tutorial, just amended to target the relevant element in my HTML. But it isn't doing anything.
Link to the CodePen.
Can you see where I'm going wrong?
.btnContainer{
width:40vw;
height:40px;
display:table;
margin:0 auto;
}
.butn{
width: 25%;
display:table-cell;
text-decoration:underline;
}
:warning: wisekodama already gave skycoder01 points
It worked (I'm on Linux). I got this error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=json. (Reason: CORS header 'Access-Control-Allow-Origin' missing). (unknown)
It looks like it's the API blocking my request, but I don't understand why :worried:
:cookie: 287 | @skycoder01 |http://www.freecodecamp.com/skycoder01
$(document).ready(function() {
$("#button").click(function() {
$("#greeting").html("Hello World");
$.getJSON("https://en.wikipedia.org/w/api.php?action=query&titles=Main%20Page&prop=revisions&rvprop=content&format=json&origin=*", function(json) {
$("#output").html(JSON.stringify(json));
});
});
});