Q:

How to remove beforeunload handler after ajax

Here I have script which will run if anyone try to refresh page, but after my ajax success response I want this script should not work or get removed. How to do this?
Script which need to be removed
$(window).on('beforeunload', function() {
  return $(".clk_mdl2").click();
});

This is ajax which will get all data after this above mentioned script should be removed automatically.
$.ajax({
  url: "<?= base_url('Users/get_data') ?>",
  type: "POST",
  data: {
    id: id
  },
  success: function(data) {
    if (data === ok) {
      //remove above  onbeforeunload script 
    }
  }
});

A:

Simply unbind this event with off:
$(window).off('beforeunload')

