Skip to content

Instantly share code, notes, and snippets.

@pamelafox
Created November 7, 2011 21:21
Show Gist options
  • Save pamelafox/1346220 to your computer and use it in GitHub Desktop.
Save pamelafox/1346220 to your computer and use it in GitHub Desktop.
CORS XHR (jQuery/Flask)
function sendData(url, data, onSuccess, onError) {
$.ajax({
url: url,
type: 'POST',
data: data,
dataType: 'json',
xhrFields: {
withCredentials: true
},
success: function(responseJSON) {
onSuccess(processJSON(responseJSON));
},
error: function(xhr, textStatus, errorThrown) {
onError(errorThrown);
}
});
}
def any_response(data):
response = make_response(data)
origin = request.headers.get('Origin', '')
if origin.endswith('mydomain.com'):
response.headers['Access-Control-Allow-Origin'] = origin
response.headers['Access-Control-Allow-Credentials'] = 'true'
return response
@woto
Copy link

woto commented Mar 5, 2012

Many thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment