I have a form at the top of my website for users to input their current progress (it's helping students with tasks when moving abroad to study), in the form of 4 checkboxes simply saying if they've achieved a certain thing yet or not. I want to wait until the user leaves the page so that whatever state the checkboxes are left in, that will be the state the database gets updated to. I want to use an ajax request to update the DB before the user leaves the page as such:
$(window).on('unload', function(){
$.ajax({
type: 'POST',
url: 'script.php',
async:false,
data: *checkbox data*
});
});
However, I then need the PHP script to redirect them to their chosen destination in the URL. Obviously for privacy reasons you can't see what URL they have chosen, but is there any way to redirect them anyway without extracting and viewing that information (and thus not breaking any browser privacy rules)?
Note: I have set async to false so that the ajax request is synchronous and therefore guaranteeing its execution.