Skip to content

Instantly share code, notes, and snippets.

@hrdtbs
Last active March 19, 2018 12:58
Show Gist options
  • Save hrdtbs/977330a4f5aefe20dc6bab4e0ee3d876 to your computer and use it in GitHub Desktop.
Save hrdtbs/977330a4f5aefe20dc6bab4e0ee3d876 to your computer and use it in GitHub Desktop.
CORS - PHP + JavaScript
const url = "";
const options = {
credentials: 'include',
mode: 'cors'
}
fetch(url, options)
.then(res => res.json())
.then((json) => {
console.log(json)
})
.catch(error => {
console.info(error)
})
}
<?php
header("Access-Control-Allow-Origin: http://localhost:3000");
header("Access-Control-Allow-Credentials: true");
header("Content-Type: application/json; charset=utf-8");
header("Access-Control-Allow-Methods: GET,POST,HEAD,OPTIONS");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment