Firstly you can join the selectors with a comma to combine the event handlers. The only difference from there is the function which gets called in the success function. Assuming the logic there is the same too you could pass the table as an argument:
$(document).ready(function () {
$("#tableA, #tableB").on("click", function () {
let $table = $(this);
$.ajax({
type: "POST",
url: "Testing.ashx",
success: function (output) {
let output = JSON.parse(output);
DrawTable($table, output);
}
})
});
});
If, for whatever reason, you need to execute completely different logic on each table element, then you could store the function name in a data attribute on the table HTML. Then you can define the functions within an object, keyed by the value of that attribute:
let tableFuncs = {
foo: () => console.log('tableA'),
bar: () => console.log('tableB')
}
$(document).ready(function() {
$("#tableA, #tableB").on("click", function() {
let $table = $(this);
// inside AJAX callback...
tableFuncs[$table.data('func')]();
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<table id="tableA" data-func="foo">
<tr>
<td>tableA</td>
</tr>
</table>
<table id="tableB" data-func="bar">
<tr>
<td>tableB</td>
</tr>
</table>
Also, as pointed out by @PeterSH in the comments, it's better practice to use common classes on repeated elements to make the code easier to maintain. With your current pattern, if you add a #tableC in the future you would need to remember to amend the JS as well. If you select by a class you just need to remember to include the class in the HTML only.