views:

60

answers:

3
   jQuery.ajax(
    {
      url:'http://en.wikipedia.org/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.

+2  A: 

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.

redsquare
is it possible like i can handle data received, iam okie with data in html format. i want to get rid of js error iam getting and want some mechanism to read received data doesnt matter in which formata data is.
Praveen Prasad
no because you cannot do an ajax request cross domain. The only way to do cross domain requests is to use jsonp which is not actually ajax (xmlhttp) as it uses script tags and a callback function. Your only option is a server side proxy on your side
redsquare
+1  A: 

You can use YQL for page fetching and get the JSONP response.

http://developer.yahoo.com/yql/console/#h=select%20*%20from%20html%20where%20url%3D%22http%3A//en.wikipedia.org/wiki/Football%22%0A

tszming
A: 

http://en.wikipedia.org/w/api.php supports a format=json parameter.

Bryan