function request(url, param) {
return new Promise(function (res) {
var url = url;
var csrftoken = getCookie('csrftoken');
data = {'csrfmiddlewaretoken': csrftoken, param: param };
$.ajax({
url: url,
type: "POST",
data: data ,
cache:false,
dataType: "json",
success: function(resp){
res(resp);
}
}) ;
})
}
request(url="/myurl/", param = param).then(function (resp) {
alert(resp.answer);
})
Или так
function request(url, param) {
var url = url;
var csrftoken = getCookie('csrftoken');
data = {'csrfmiddlewaretoken': csrftoken, param: param };
return $.ajax({
url: url,
type: "POST",
data: data ,
cache:false,
dataType: "json",
}) ;
}