/**
* @param {String} url - ajax url
* @param {Object} data - post data for ajax call
* @param {Object} elem - element that initiated the event
* @param {Function} callback - callback method to execute after AJAX success
*/
_ajax: function (url, data, elem, callback) {
$.extend(data, {
'form_key': $.mage.cookies.get('form_key')
});
$.ajax({
url: url,
data: data,
type: 'post',
dataType: 'json',
context: this,
beforeSend: function () {
elem.attr('disabled', 'disabled');
},
complete: function () {
elem.attr('disabled', null);
}
})
.done(function (response) {
if (response.success) {
callback.call(this, elem, response);
} else {
var msg = response.error_message;
if (msg) {
alert({
content: $.mage.__(msg)
});
}
}
})
.fail(function (error) {
console.log(JSON.stringify(error));
});
},
1 Like
dmitrii_fediuk
(Dmitrii Fediuk)
Split this topic
2