Files
tripwithbonus/static/v2/js/service/api.js
2025-01-08 21:33:19 +03:00

33 lines
961 B
JavaScript

class api {
constructor(props) {
this.url = props.url;
this.data = props.data;
this.data_type = props.data_type;
this.type = props.type || 'POST';
this.success_callback = props.success;
this.error_callback = props.error_callback;
}
ajaxRequest (){
if (!this.url) return;
let request_data = {
headers: {"X-CSRFToken": $('input[name=csrfmiddlewaretoken]').val()},
url: this.url,
type: this.type,
data: this.data,
success: function (data) {
if (this.success_callback) this.success_callback(data)
}, error: function (data) {
if (this.error_callback) this.error_callback(data)
}
}
if (this.data_type === 'formData'){
request_data.processData = false
request_data.contentType = false
}
$.ajax(request_data);
}
}