Skip to content

Instantly share code, notes, and snippets.

@KeenthemesHub
Created April 7, 2023 03:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save KeenthemesHub/b763755828ad294b9db9a3cc2d7f206a to your computer and use it in GitHub Desktop.
Save KeenthemesHub/b763755828ad294b9db9a3cc2d7f206a to your computer and use it in GitHub Desktop.
starterkit/resources/mix/common/button-ajax.js
$(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');
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.reload();
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment