My AJAX/Java knowledge is very limited so this might sound like a stupid and very easy question, but here I go.
I am trying to execute a very simple one line mysqli query after clicking a link on a php page. This query has to be executed in the background, so without reloading the page, so I would need AJAX to do that.
EDIT: This is the code I have now.
The PHP page (notes_checked.php) with my query:
if ($user_ok == true) {
mysqli_query($db_conx, "UPDATE users SET notescheck=now() WHERE username='$log_username' LIMIT 1");}
else {
exit();
}
The Javascript function I execute when clicking:
<script>
function notesChecked() {
document.getElementById("notbadge").style.background = "#B0B0B0";
document.getElementById("notbadge").innerHTML = "0";
$.ajax({
type: "POST",
url: 'php_includes/notes_checked.php',
data: data,//post data
success: function()
{
alert("You just checked your notes!");
}
});
}
</script>
The link on my main page:
<a onclick="notesChecked()">Checked</a>
So this script sets the counter back at 0 and changes the background color of the span when the user clicks on it. Now I have to execute the mysqli query so this number stays 0 when the user refreshed the page or comes back later.
Anyone who can tell me if there's an easy way to do this? Thanks!