I have a web app where I need to call a php function with parameters when the user navigates away from the page. This functionality doesn't need to be too sophisticated, simply when the user clicks another link on the page or goes to a different URL should suffice. Needed for a CRUD app to release the record lock which is executed via the function call (sproc wrapper).
php code
if (isset($_GET['modify'])) {
....
} else {
// Putting the function here causes excessive calls
}
wrapper
function record_lock($row_id, $username, $end_lock){
$stmt = mssql_init('spRecordLocks');
mssql_bind($stmt, '@RowId', $row_id, SQLVARCHAR, false, false, 50);
mssql_bind($stmt, '@Username', $username, SQLVARCHAR, false, false, 50);
mssql_bind($stmt, '@EndLock', $end_lock, SQLVARCHAR, false, false, 50);
$result = mssql_execute($stmt);
$array = return_array($result, $stmt);
return $array;
}
After researching, seems I need to make an ajax call though I am unsure of the implementation. Do I create a window.onunload = func.. Hoping someone can point me in the right direction. Thanks.