I'm a newbie at programming with AJAX and beginner at PHP programming. I'm not sure why, but when a user clicks an arrow to "Upvote" a post repeatedly and very fast, the PHP login_check decides that the user is no longer logged in. The program works if I click the arrow at a normal speed, but when I rapid fire it gets weird.
PHP code:
<?php
include "db_connect.php";
include "functions.php";
sec_session_start();
I was wondering if this is a definite case of race conditions and what I could do to prevent it--
AJAX code:
$(document).ready(function() {
$("#upvotearrow").click(function() {
setTimeout(function() { }, 500);
$resdiv=$("#upvotedownvote_resultalert");
$content=$("#upvotedownvote_resultalert_content");
$.ajax({
type: "POST",
url: "../secure/process_upvotedownvote.php",
data: { vote: "upvote", poemid: $("#poemidfield").val() },
dataType:"HTML"
})
.done(function(param) {
if (param=="true_upvote") {
$content.html("Upvote registered!");
$resdiv.css("visibility", "visible");
}
else {
$content.html("Invalid request");
$resdiv.css("visibility", "visible");
}
});
});
$("#downvotearrow").click(function() {
setTimeout(function() { }, 500);
$resdiv=$("#upvotedownvote_resultalert");
$content=$("#upvotedownvote_resultalert_content");
$.ajax({
type: "POST", //POST data
url: "../secure/process_upvotedownvote.php", //Secure upvote/downvote PHP file
data: { vote: "downvote", poemid: $("#poemidfield").val() }, //Get type of vote and poem_id in URL
dataType:"HTML" //Set datatype as HTML to send back params to AJAX function
})
.done(function(param) { //Param- variable returned by PHP file
if (param=="true_downvote") {
$content.html("Downvote registered!");
$resdiv.css("visibility", "visible");
}
else {
$content.html("Invalid request");
$resdiv.css("visibility", "visible");
}
});
});
});
The website with a live demo can be viewed here.
TO LOG IN, JUST USE THIS EMAIL: asdf@gmail.com AND THIS PASSWORD: asdf123
Thanks in advance for any advice!