clara/resources/mix/common/button-ajax.js

28 lines
696 B
JavaScript
Raw Normal View History

2023-09-26 09:51:59 +00:00
$(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');
2024-02-01 04:31:06 +00:00
var redirect = $(this).data('redirect');
2023-09-26 09:51:59 +00:00
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) {
2024-02-01 04:31:06 +00:00
window.location = redirect;
2023-09-26 09:51:59 +00:00
}
});
});