javascript - Cannot carry out Ajax request from wikipedia -


i want use wikipedia api in project grab images of people, fail. use url:https://en.wikipedia.org/w/api.php?action=query&prop=pageimages&titles=albert%20einstein&pithumbsize=100 when console browser says following

refused execute script 'https://en.wikipedia.org/w/api.php?action=query&prop=pageimages&titles=albe…callback&callback=jquery22409288979864744966_1470068280411&_=1470068280412' because mime type ('text/html') not executable, , strict mime type checking enabled. 

my code

var general = {     // url quote api     url: 'http://api.forismatic.com/api/1.0/',     // display author name if s/he's unknown     unknownauthor: 'uknown',     // base url tweet links generation     tweeturl: 'http://twitter.com/home?status=',     wikiurl:'https://en.wikipedia.org/w/api.php?action=query&prop=pageimages&titles=albert einstein&pithumbsize=100&callback=wikicallback' };  var wikirequest = function() {     $.ajax({       url:general.wikiurl,       datatype: 'jsonp',       success: function(wikdata) {       console.log(wikdata);       //var image = wikidata.       displayquote(image);       } // end of success     }); }// wikirequest  wikirequest(); 

pen

has met same issue?

you trying load data using jsonp, making request url returns html document. jsonp requests have answered javascript programs (since fundamental feature of how work … , why dangerous , should avoided in favour of plain json , cors).

to make return jsonp need provided 2 additional query string parameters:

  • format=json
  • callback=yourcallbackname

yourcallbackname name of function should executed , passed data fetching argument. ajax libraries generate name (and function itself) dynamically when specify callback=?.


Comments