I have been working on a really large html form which has a reset button.
On reset, there is a database operation which takes place.
I have a javascript function as such, which is called on reset:
function clearDatabaseOfAnySavedForm() {
window.name = 1;
$.post('assets/scripts/reset-form.php');
window.location.reload();
$(document).load().scrollTop(0);
return false;
}
The code for the php file referenced in this function is:
<?php
//Authcate
$authcate = xxxxx;
$username = "xxxxx";
$password = "xxxxx";
//$hostname = "xxxxx";
$hostname = "xxxxx";
$database = "xxxxx";
$conn = mysql_connect($hostname, $username, $password);
mysql_select_db($database, $conn) or die( "Unable to select database");
if (!empty($authcate)) {
$table = "xxxxx";
$sqlSelectQuery = "SELECT * FROM $table WHERE authcate = '$authcate'";
$selectResults = mysql_query($sqlSelectQuery);
$selectNumResults = mysql_num_rows($selectResults);
if ($selectNumResults > 0) {
$sqlUpdateQuery = "DELETE FROM $table WHERE authcate = '$authcate'";
$result = mysql_query($sqlUpdateQuery);
}
}
mysql_close($conn);
}
All this works fine is all browsers, but for some reason, the php file doesn’t get invoked in Firefox.
Does anyone have any ideas of suggestions?
Expanding on @epascarello’s answer, you probably want to use a callback function, this will execute code when your post is done. Read about it here
And you don’t need the scrollTop and return false;
If you don’t know what a callback function is, read about it here. I remember when I first started with javascript, it was a very unusual concept to grasp.