最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - read wikipedia url's content using jquery, cross domain network call - Stack Overflow

programmeradmin4浏览0评论
   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
Add a ment  | 

3 Answers 3

Reset to default 7

There 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

发布评论

评论列表(0)

  1. 暂无评论