-1

I found in stackoverflow an answer that retrieves the infobox from wikipedia given a url.

var url="http://en.wikipedia.org/w/api.php?action=parse&format=json&page=" + interests[index].name + "&redirects&prop=text&callback=?";
var html = "";

$.getJSON(url,function(data){
    wikiHTML = data.parse.text["*"];
    $wikiDOM = $("<document>"+wikiHTML+"</document>");
    result_html += '<p>' + $wikiDOM.find('.infobox').html() + '</p>';
});

But i am getting the following error:

Uncaught TypeError: Cannot read property 'text' of undefined 

The url is valid, although the searchterm has spaces. Example:

Full Metal Alchemist would be the interests[index].name.

Huangism
  • 16,278
  • 7
  • 48
  • 74
João
  • 331
  • 1
  • 3
  • 17
  • I think you'll have a big problem here since you are calling a 3rd party site from you script - which is a security violation (search for cross site scripting for more info). What you should do is write a server side script for your site that will take the info you need from wikipedia and call your page (which will be hosted on the same site with the javascript). – developer82 Jul 24 '14 at 09:58
  • but if i print the $wikiDOM.find('.infobox').html(). It returns something and the error i am getting is not that one. although i recognise that it might happen. but i think in this case wikipedia services use jsonP which lets me do it without that problem. – João Jul 24 '14 at 09:59
  • 1
    your code [**works !!**](http://jsfiddle.net/28Np5/) – Mithun Satheesh Jul 24 '14 at 10:04
  • Hum thx then it might be the placement of the function. ty very much – João Jul 24 '14 at 10:05
  • although it works in jsfiddle i am still getting the error i describe on top – João Jul 24 '14 at 10:11
  • 1
    Your error means that `data` doesn't have a property `parse`. Use `console.log(data)` and look at the content in your browsers debugger. – RoToRa Jul 24 '14 at 11:01

1 Answers1

0

From what i realised is that some interests of mine dont have wikipedia pages and for that i dont get any response.

João
  • 331
  • 1
  • 3
  • 17
  • Not quite true. The point is that you're not *searching* the topic, you're hardcoding a page title in your request. You want the [opensearch API](https://www.mediawiki.org/wiki/API:Opensearch). – Nemo Apr 29 '15 at 07:38