Top19 Top19 - 4 months ago 9
JSON Question

jQuery not returning JSON despite getting it back via the browser

I can't get the following lines of code to return JSON, or even to run my simple alert() function embedded inside. I know the URL is correct, because when I paste it in the browser it returns JSON. Does anyone know what could be the problem here?

I've tried this in CodePen and JSFiddle (making sure to include jQuery) on Chrome, but no such luck.

$.getJSON("https://en.wikipedia.org/w/api.php?action=query&prop=info&format=json&callback=?inprop=url&pageids=18630637"
, function(data) {
alert("success");
console.log(data);
});

Answer

You have a missing & in your querystring. Change:

&callback=?inprop...

To:

&callback=?&inprop...

See JSFiddle