wardialer
wardialer

Reputation: 51

JSON: Retrieving JSON file from another domain

After awhile of not using JSON, I'm a little rusty on the possibility of requestiing the data from another domain/web-server.

<?php header('Access-Control-Allow-Origin: *');
  if(!empty($_GET['file'])){
?>
  jsonFile = 'data/<?php echo $_GET['file']; ?>';
<?php
  }
?>

Is there a way to do this without using JSONP? I think the way I have my code setup, it queries from a data/ folder. That data folder is also available on the other web server. Any thoughts? All appreciated.

Upvotes: 2

Views: 55

Answers (1)

Ram
Ram

Reputation: 144699

You don't need that header here. Presence of Access-Control-Allow-Origin matters only when you are requesting a resource from another domain via browser. And it's the target server that should return the header not the client. Since you are using PHP you just need to request the resource normally.

Check the MDN's CORS article for more information.

Upvotes: 3

Related Questions