I am trying to use the $.getJSON
function to fetch data from the Wikipedia API which uses HTTPS. I used this same snippet of code to request JSON data from the OpenWeather API which uses HTTP. When I check the browser console after sending the request I get this error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=doom&srnamespace=0. (Reason: CORS header 'Access-Control-Allow-Origin' missing)
Is the Wikipedia API's use of HTTPS causing this? My code is listed below. Thank you for the help.
$("#submit").click(function() {
var searchQuery = $("#input").val();
var apiUrl = "https://en.wikipedia.org/w/api.php?action=query&format=json&list=search&srsearch=" + searchQuery + "&srnamespace=0";
$.getJSON(apiUrl, function(json) {
...
});
});