Reputation: 345
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);
});
Upvotes: 2
Views: 61
Reputation: 11172
Link returns invalid json according to http://jsonlint.com/
Error: Parse error on line 1: /**/inpropurl({ "b ^ Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '[', got 'undefined'
/**/inpropurl({"batchcomplete":"","query":{"pages":{"18630637": {"pageid":18630637,"ns":0,"title":"Translation","contentmodel":"wikitext","pagelanguage":"en","pagelanguagehtmlcode":"en","pagelanguagedir":"ltr","touched":"2016-07-08T07:40:24Z","lastrevid":726282436,"length":83042}}}})
Upvotes: 0
Reputation: 1188
You are receiving bad json because the url is wrong. try with this url:
Upvotes: 1
Reputation: 16804
You have a missing &
in your querystring. Change:
&callback=?inprop...
To:
&callback=?&inprop...
See JSFiddle
Upvotes: 5