Last active
March 19, 2018 12:58
-
-
Save hrdtbs/977330a4f5aefe20dc6bab4e0ee3d876 to your computer and use it in GitHub Desktop.
CORS - PHP + JavaScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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