I have created a common ajax call function for my application for optimizing code. the problem is while I call the function its freeze page. Please check below JS:
$(fuction(){
$('.btn').click(function(){
var data = getData('myaction/getinfo', []);
})
});
function getData(url, data) {
var result = "";
$.ajax({
url: url,
type: 'POST',
async: false,
data: data,
error: function () {
console.log('error');
$('.custom-loader').fadeOut("slow");
},
beforeSend: function () {
$('.custom-loader').fadeIn("slow");
},
complete: function () {
$('.custom-loader').fadeOut("slow");
},
success: function (res, status) {
result = res;
$('.custom-loader').fadeOut("slow");
}
});
return result;
}
While I click a button, ajax request working pretty well but loader not showing until ajax return response (unable to click until response return).
If I on async with async: true
this will continue execution code which breaks functionality (Next execution depend on ajax response). Can anyone help me with this?
Thanks an advance!