clara/resources/mix/common/button-ajax.js
2024-02-01 11:31:06 +07:00

28 lines
696 B
JavaScript

$(document).on('click', '.button-ajax', function (e) {
e.preventDefault();
var action = $(this).data('action');
var method = $(this).data('method');
var csrf = $(this).data('csrf');
var reload = $(this).data('reload');
var redirect = $(this).data('redirect');
axios.request({
url: action,
method: method,
data: {
_token: csrf
},
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
})
.then(function () {
if (reload) {
window.location = redirect;
}
});
});