Created
November 7, 2011 21:21
-
-
Save pamelafox/1346220 to your computer and use it in GitHub Desktop.
CORS XHR (jQuery/Flask)
This file contains 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
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); | |
} | |
}); | |
} |
This file contains 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
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Many thanks!