Dear All.
I’m trying to implement a query from the Wiktionary to receive some information which I’d like
to display in my learning cards.
This is my query function
function getHTML(term, callback) {
console.log("***** function getHTML *****");
$.ajax({
url: 'https://en.wiktionary.org/w/index.php?title='+term,
type: 'post',
cache: false,
success: function(data){
let erg=ExtractLatinHTML(data);
if ( true == erg[0] )
callback(erg[1]);
},
error: function (jqXHR, exception) {
var msg = 'AJAX Error: ';
if (jqXHR.status === 0) {
msg += 'Not connect.\n Verify Network.'+exception;
} else if (jqXHR.status == 404) {
msg += 'Requested page not found. [404]';
} else if (jqXHR.status == 500) {
msg += 'Internal Server Error [500].';
} else if (exception === 'parsererror') {
msg += 'Requested JSON parse failed.';
} else if (exception === 'timeout') {
msg += 'Time out error.';
} else if (exception === 'abort') {
msg += 'Ajax request aborted.';
} else {
msg += 'Uncaught Error.\n' + jqXHR.responseText;
}
//alert(msg);
setError(msg);
}
});
}
While testing this, I received the following error message in the Inspector - in Anki on my desktop as well as on Ankidroid on my tablet:
Access to XMLHttpRequest at 'https://en.wiktionary.org/w/index.php?title=robur' from origin 'null' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I developed this on my desktop, and for the first time, I got the same error … CORS means Cross-Origin Resource Sharing, as I found out. On my Linux desktop, I found an extension for Google Chrome where CORS can be toggled on/off … using this, my query was working on the desktop Google Chrome.
Here’s what I have tried so far:
Found this here on MDN … but it goes far beyond my knowledge.
Found a discussion here at Stackoverflow concerning this … so I added
headers: { 'Access-Control-Allow-Origin': 'https://en.wiktionary.org' },
to my query above … but it doesn’t work. I think I have to set something in this query header, but I have not really understood what goes on here …
Or can we simply toggle this “CORS” on and off, as it’s possible in the Google Chrome browser on the desktop?
Has anyone of you experience with this? I would appreciate any hint to make this query work …
Thanks in advance for your efforts, Frank