JSFiddle - React, Tailwind, and code Playground

HTML

<input type='button' id='idd' value='click'/>

JavaScript

$(window).unload(function(e){
    e.preventDefault();
    $(window).trigger('customTrigger');   

});


$(window).bind('customTrigger',function(){

alert('call your ajax here');
});