0

The AJAX function below accesses my PHP script. The intention was to delete blank MySQL entries when the user closes the page.

window.onbeforeunload would have been perfect to achieve this, but in the latest version of Chrome it only seems to allow alerts to be run.

Wondering if there are any comparable alternatives to this approach?

Code sample (doesn't work in Chrome):

window.onbeforeunload = function() {
saveFormData();
return null;
}

function saveFormData() {
$.post("<?php echo site_url('resume/cleanup'); ?>", { resume_id: "<?php echo $this->session->userdata('resume_id'); ?>" } );
}
jsuissa
  • 1,754
  • 6
  • 30
  • 64

1 Answers1

1

This is not dependable. If the user loses their connection no data will be sent. You're better off running a Cron job to clean up left-over data.

Diodeus - James MacFarlane
  • 112,730
  • 33
  • 157
  • 176