Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/bfontaine/jquery-djangocsrf

A lightweight jQuery plugin to automatically add Django CSRF token to your AJAX calls
https://github.com/bfontaine/jquery-djangocsrf

django jquery js

Last synced: 14 days ago
JSON representation

A lightweight jQuery plugin to automatically add Django CSRF token to your AJAX calls

Awesome Lists containing this project

README

        

# jQuery Django CSRF Plugin

[![Build Status](https://travis-ci.org/bfontaine/jquery-djangocsrf.svg?branch=master)](https://travis-ci.org/bfontaine/jquery-djangocsrf)

The **djangocsrf** jQuery plugin makes it easy to use AJAX calls with Django’s
CSRF token.

## Installation

[Download][release-0.1.1] and include the script *after* the jQuery library and
the Cookie library:

```html

```

[release-0.1.1]: https://github.com/bfontaine/jquery-djangocsrf/releases/download/0.1.1/jquery.djangocsrf-0.1.1.min.js

## Usage

Enable the plugin:

```js
$.djangocsrf( "enable" );
```

That’s all! After that, all AJAX calls made through jQuery to the current
domain will include an `X-CSRFToken` header set to the client’s token.

Disable the plugin with `$.djangocsrf( "disable" )`, and query its current
state with `$.djangocsrf()`.

## Tests

$ npm install -g grunt-cli
$ npm install -d

Requires Node. Start the server:

$ node test/server.js

Then open `http://0.0.0.0:8124/test/index.html` in your browser.

Basic tests can also be run with `grunt`.