jQuery.ajax(
{
url:'',
type:'get',
dataType:'jsonp',
success:function(data){alert(data);},
}
i want to read wikipedia page from my domain using jQuery, iam doing as above. as expected wikipedia is sending data as pure html, but when we use $.ajax to get cross domain data it expects data received to be in json format so iam getting error and unable to read the wikiepedia response.
please suggest me how can i read wikipedia url using jquery/javascript (without involving any server side tech) also is there any api available through which i get json from wikipedia.
jQuery.ajax(
{
url:'http://en.wikipedia/wiki/Football',
type:'get',
dataType:'jsonp',
success:function(data){alert(data);},
}
i want to read wikipedia page from my domain using jQuery, iam doing as above. as expected wikipedia is sending data as pure html, but when we use $.ajax to get cross domain data it expects data received to be in json format so iam getting error and unable to read the wikiepedia response.
please suggest me how can i read wikipedia url using jquery/javascript (without involving any server side tech) also is there any api available through which i get json from wikipedia.
Share Improve this question asked Jun 26, 2010 at 9:09 Praveen PrasadPraveen Prasad 32.1k20 gold badges76 silver badges106 bronze badges 1- 2 Good question, but I think this can't be done without a server side relay that does the fetching. Can you use any server side languages? – Pekka Commented Jun 26, 2010 at 9:11
3 Answers
Reset to default 7There is a Wikipedia API (more precisely, MediaWiki, the engine of Wikipedia, has an API). You can read more about it here: http://www.mediawiki/wiki/API
Here is a jQuery example on how to fetch the formatted content of the "Football" page:
$.getJSON("http://en.wikipedia/w/api.php?action=parse&format=json&callback=?", {page:"Football", prop:"text"}, function(data) {console.log(data);});
The endpoint has to be configured to serve jsonp which in this case it is not. It will not magically transform the normal html response type into jsonp for you. You will need to create a proxy on your server which will serve you the remote content for example if you are using php then check out this link.
You can use YQL for page fetching and get the JSONP response.
http://developer.yahoo./yql/console/#h=select%20*%20from%20html%20where%20url%3D%22http%3A//en.wikipedia/wiki/Football%22%0A