I have been making ajax requests many times. I need to know which button I clicked
<button class="ajax-btn" onclick="function_1();">Ajax 1</button>
<button class="ajax-btn" onclick="function_2();">Ajax 2</button>
...
<button class="ajax-btn" onclick="function_10();">Ajax 10</button>
// ajax request for each button
var ajaxBtnVal = ""; // keep button text
$(document).ajaxStart(function(e, xhr, options) {
$(".ajax-btn").addClass('spinner spinner-white spinner-right disabled');
ajaxBtnVal = $(".ajax-btn").text();
$(".ajax-btn").text('Processing...');
// which button was clicked ?
});
$(document).ajaxComplete(function() {
$(".ajax-btn").removeClass('spinner spinner-white spinner-right disabled');
$(".ajax-btn").text(ajaxBtnVal);
});
2
Answers
This should show you which button was clicked.