django+jquery ajax post csrf 配置:jquery
<body>ajax
{% csrf_token %}
<script>
var csrftoken = jQuery(「[name=csrfmiddlewaretoken]」).val();docker
function docker_build_ver(url,pk) {
bootbox.prompt({
size: 「small」,
title: 「請輸入版本號,如v1.1」,
callback: function(result) {
if (result != null) {
if (ulist.length == 1 || ulist.length > 3){
bootbox.alert({size: ‘small’, message: ‘輸入的版本號不正確,請從新輸入!’});
}else {
postData(url,{pk:pk ,result: result});
}
} else {}
}
});
}django
function postData(url,data) {
$.ajaxSetup({
data: {csrfmiddlewaretoken: ‘{{ csrf_token }}’ },
});
$.ajax({
url: url,
data: data,
type: ‘post’,
dataType: ‘json’
}).done(function () {});json
} post
</scrip>ui
</body>url