Skip to content

Instantly share code, notes, and snippets.

@pkarman
Created May 13, 2014 14:37
Show Gist options
  • Select an option

  • Save pkarman/a32bc782ad4744621882 to your computer and use it in GitHub Desktop.

Select an option

Save pkarman/a32bc782ad4744621882 to your computer and use it in GitHub Desktop.
$.ajaxSetup({
xhrFields: {
withCredentials : true // allow FF to send auth cookie
},
headers: {
"X-Requested-With" : "xmlhttprequest" // tell server we're ajax
}
});
@pkarman
Copy link
Copy Markdown
Author

pkarman commented May 13, 2014

Catalyst example in Root->auto()

# always set CORS headers so we can use the API cross-domain
# use explicit Origin from request since some clients (FF)
# do not like a wildcard *
my $res = $c->res;
$res->header(
    'Access-Control-Allow-Methods' => 'GET,PUT,POST,DELETE,OPTIONS' );
$res->header( 'Access-Control-Allow-Credentials' => 'true' );
$res->header( 'Access-Control-Allow-Origin' =>
        ( $c->request->header('Origin') || '*' ) );
$res->header( 'Access-Control-Allow-Headers' =>
        'Content-Type, X-Requested-With, Origin, Accept, *' );

@davehodg
Copy link
Copy Markdown

Worth noting that the .ajax call needs to be async otherwise Firefox will whine at you and give:

Exception... "A parameter or an operation is not supported by the underlying object", as noted here:

http://stackoverflow.com/questions/16677893/evil-firefox-error-a-parameter-or-an-operation-is-not-supported-by-the-under

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