function request(url, param) {
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){
alert(resp.answer);
}
}) ;
}
answer = request(url="/myurl/", param = param)
return $.ajax(...)
function request(url, param) {
// ...
return $.ajax({
// ...
});
}
request("/url", param).done(function (data) {
console.log(data.answer);
});
(async () => {
const answer = await request("/url", param);
console.log(answer);
})();
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",
}) ;
}