Skip to content

Instantly share code, notes, and snippets.

@XingMXTeam
Last active April 25, 2018 07:27
Show Gist options
  • Save XingMXTeam/a6aa7947dace282a4b0acb6088a8045c to your computer and use it in GitHub Desktop.
Save XingMXTeam/a6aa7947dace282a4b0acb6088a8045c to your computer and use it in GitHub Desktop.
//1
var xhr = new XMLHttpRequest();
xhr.open('GET', url);
xhr.withCredentials = true;
xhr.send();
//2
$.ajax({
url: a_cross_domain_url,
xhrFields: {
withCredentials: true
}
});
//server
const express = require('express');
var app = express();
app.get('/specific-allow-origin-with-credentials', (req, res) => {
res.set({
'Access-Control-Allow-Origin': 'http://index.com:4001',
'Access-Control-Allow-Credentials': true
});
res.status(200).end('I got your cookie: ' + req.headers.cookie);
});
app.listen(4001, () => console.log('listening to 4001'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment