Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

350
Views
Access-Control-Allow-Origin: Access for all users just to one site

I'm currently coding a php website which reads certain values from a json file from my server. Now when i request the xmlhttp request to my server, i get the Access-control-allow-origin ERROR in console. I already find out i have to set Access-control-allow-origin: *; in my Apache configuration but i don't want to use * because I don't want to give everyone access to my website. So how can i just give permission for one json file to every client?

var requestURL = 'https://myWebsite/blabla.json';
var request = new XMLHttpRequest();
request.open('GET', requestURL);
request.responseType = 'json';
request.send();

request.onload = function() {
  var response = request.response;
  jackpot = response.items[0].value;

  var inner = document.getElementById("myid");
inner.innerHTML = jackpot+" EURO";

this is my js code and i always get the Error, except i use Access-control-allow-origin: *, which i dont want to use because its unsave.

Please care im little new to web coding so im not really professional sorry.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

In your PHP backend, allow only to your domain for Access-control-allow-origin not *. So that it will be safe.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!