Skip to content

Instantly share code, notes, and snippets.

@Djiit
Forked from jhuckabee/gist:810552e99959eacbbea9
Last active September 30, 2015 09:37
Show Gist options
  • Save Djiit/c91dc8bc37ef9fc8160e to your computer and use it in GitHub Desktop.
Save Djiit/c91dc8bc37ef9fc8160e to your computer and use it in GitHub Desktop.
django-ajax
<polymer-element name="django-ajax" extends="core-ajax">
<script>
Polymer({
getCSRFCookie: function() {
b = document.cookie.match('(^|;)\\s*csrftoken\\s*=\\s*([^;]+)');
return b ? b.pop() : '';
},
ready: function() {
this.super();
this.headers = {
"X-CSRFToken": this.getCSRFCookie(),
"X-Requested-With": "XMLHttpRequest"
};
}
});
</script>
</polymer-element>
@Djiit
Copy link
Author

Djiit commented Jan 12, 2015

X-CSRFToken allow you to use django-ajax on POST request.
X-Request-With enabled "request.is_ajax()" test on the Django side.

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