Forked from jhuckabee/gist:810552e99959eacbbea9
Last active
September 30, 2015 09:37
-
-
Save Djiit/c91dc8bc37ef9fc8160e to your computer and use it in GitHub Desktop.
django-ajax
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
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
X-CSRFToken allow you to use django-ajax on POST request.
X-Request-With enabled "request.is_ajax()" test on the Django side.