I have a Invision Community forum running on v4.3.6, with two themes. I am working on a newer one, and I want to display online/total members given by a json db.
To do this, I made this script that works only on a old theme:
<p style="margin: 0;">
Online <img alt="on.svg" src="https://www.xxxxxx.xxxxx/forum/uploads/on.svg" style="width:8px; margin: 0 0 3px 0;"><span id="d-online"></span> | Membri în total <img alt="total.svg" src="https://www.xxxxxx.xxxxxx/forum/uploads/total.svg" style="width: 8px; margin: 0 0 3px 0;"><span id="d-total"></span>
</p>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script><script type="text/javascript">
$(document).ready(function(){
$.getJSON('https://XXXXXXXXXX.xyz/morpheus/db.json', function(jd) {
$('#d-online').append(" ", jd.online);
$('#d-total').append(" ", jd.total);
});
});
</script>
That should give me this: https://i.stack.imgur.com/4pUBe.png
On the newer theme that I'm working on, chrome outputs this error in console: https://i.stack.imgur.com/JDM4X.png
I tried
Making a .htaccess file in the root folder of the website, with these rules
Header add Access-Control-Allow-Origin "*"
Header add Access-Control-Allow-Headers "origin, x-requested-with, content-type"
Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
But it didn't work at all, the error still shows up.
Instead of *
on the Access-Control-Allow-Origin
field, I tried to put the website that hosts that db.json as origin, but it didn't work.
So I tried putting the htaccess file inside /forum/ folder, where the forum is located, but nothing.
I tried following the steps on this website, but nothing, javascript nor php didn't work.
Error:
Access to XMLHttpRequest at 'https://xxxxxxxxxx.xyz/morpheus/db.json?csrfKey=3e4139dc5b1b138ab0bcbdf7d20e4735' from origin 'https://www.xxxxxxxxxx.ro' has been blocked by CORS policy: Request header field X-Requested-With is not allowed by Access-Control-Allow-Headers in preflight response.
Here are some screenshots of the db.json
headers in the chrome console:
https://i.stack.imgur.com/jEVwm.png
https://i.stack.imgur.com/CAAPC.png
How can I fix this?