1

I am developing an application that fetch keywors from wikipedia using the api. I am using getJSON in jquery. My code is

jQuery( document ).ready(function($) {
    console.log( "System Ready" );
    $('#searchInput').keypress(function(tval){
        if (tval.which !== 0 && !tval.ctrlKey && !tval.metaKey && !tval.altKey) {
            console.log($(this).val());
             var wikiurl = "http://en.wikipedia.org/w/api.php?"
                $.getJSON( wikiurl, {
                action: "opensearch",
                serach: $(this).val(),
                format: "json"
                })
                .done(function( data ) {
                    console.log(data);

                });
    }   
    });

});

But it is getting error

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://en.wikipedia.org/w/api.php?&action=opensearch&serach=&format=json. This can be fixed by moving the resource to the same domain or enabling CORS.

But the Example in http://api.jquery.com/jquery.getjson/

is working fine

<script>
(function() {
var flickerAPI = "http://api.flickr.com/services/feeds/photos_public.gne?jsoncallback=?";
$.getJSON( flickerAPI, {
tags: "mount rainier",
tagmode: "any",
format: "json"
})
.done(function( data ) {
$.each( data.items, function( i, item ) {
$( "<img>" ).attr( "src", item.media.m ).appendTo( "#images" );
if ( i === 3 ) {
return false;
}
});
});
})();
</script>

No Cross Site Request Errors. How this happens? How can I resolve? I am testing the code on my localhost. and Using Firefox and Firebug.

Ranjith Siji
  • 1,125
  • 3
  • 12
  • 19

0 Answers0