Hi All,
I need your help please. I’ve been struggling for a week now trying to figure out by my self how to solve but I raise the white flag.
I have two issues:
-
Preflight request not passing the access control test
-
If the first one is successful, I don’t know how to handle the response using a callback function.
Below is my code & the returned error in the console:
$(document).ready(function () {
var $keyWord = $("#searchKeyWord").val();
$(".btn").on("click", function () {
var apiCall = $.ajax({
url: 'https://en.wikipedia.org/w/api.php?action=opensearch&format=json&origin=*&search=' + $keyWord,
contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
dataType: 'json',
headers: {'Access-Control-Allow-Origin': 'http://localhost:3000'},
success: handleData,
});
});
function handleData(data) {
console.log(data);
};
})
Thanks a lot for your help