In my HTML document I have this code:
<a id='ajax-trigger' href='...', data-one='...'>
Trigger AJAX!
</a>
And in a external, not my own and uneditable JS library I have something like this:
$('#ajax-trigger').on('click', function() {
$.ajax({
type: "POST",
url: a.attr('href'),
data: postData,
dataType: 'json',
success: function(data) {
// handle Ajax success...
},
error: function(jqXHR, textStatus, errorThrown) {
// handle Ajax error...
}
});
});
With the above code in place, when the <a> link is clicked then the Ajax request is triggered.
Now, to further manipulating the DOM after a success Ajax response, I'm looking for a way to listen the success Ajax response local event related to the Ajax triggering element without changing the JS library source code. That is, I would like to add an Ajax success event listener for the <a> element in the HTML document without changing the original JS library. Maybe, something like this (note: ajaxSuccess is just an example):
<a id='ajax-trigger' href='...', data-one='...'>
Trigger AJAX!
</a>
<script type="text/javascript">
$(document).ready(function() {
$('#ajax-trigger').on('ajaxSuccess', function() {
// handle Ajax success in addition to the
// Ajax success handler in the JS library...
});
});
</script>
Is it possible with jQuery/JS?