Created
June 4, 2019 06:55
-
-
Save caramelchocolate/d5a9f93127006c830b1fc02ecdce8641 to your computer and use it in GitHub Desktop.
djangoでjquery(javascript)でのajaxを使う場合
This file contains hidden or 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
// ref: https://docs.djangoproject.com/en/2.2/ref/csrf/#ajax | |
// 下記の関数のソースは上記の公式ドキュメントを参考 | |
var csrftoken = Cookies.get('csrftoken'); | |
$.ajaxSetup({ | |
headers: { | |
'X-CSRFToken': csrftoken | |
} | |
}); | |
$.ajax({ | |
type: 'POST', | |
url: request_url, | |
dataType: "json" | |
}).done((data, textStatus, jqXHR) => { | |
// ... | |
}).fail( (data) => { | |
// ... | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment