I can't for the life of me figure out why this is happening.
This is kind of a repost (submitted to stackoverflow, but maybe a server issue?).
I am running a javascript log out function called logOut() that has make a jQuery ajax call to a php script...
function logOut(){
var data = new Object;
data.log_out = true;
$.ajax({
type: 'POST',
url: 'http://www.mydomain.com/functions.php',
data: data,
success: function() {
alert('done');
}
});
}
the php function it calls is here:
if(isset($_POST['log_out'])){
$query = "INSERT INTO `token_manager` (`ip_address`) VALUES('logOutSuccess')";
$connection->runQuery($query); // <-- my own database class...
// omitted code that clears session etc...
die();
}
Now, 18 hours out of the day this works, but for some reason, every once in a while, the POST data will not trigger my query. (this will last about an hour or so). I figured out the post data is not being set by adding this at the end of my script...
$query = "INSERT INTO `token_manager` (`ip_address`) VALUES('POST FAIL')";
$connection->runQuery($query);
So, now I know for certain my log out function is being skipped because in my database is the following data:
if it were NOT being skipped, my data would show up like this:
I know it is being skipped for two reasons, one the die() at the end of my first function, and two, if it were a success a "logOutSuccess" would be registered in the table.
Any thoughts? One friend says it's a janky hosting company (hostgator.com). I personally like them because they are cheap and I'm a fan of cpanel. But, if that's the case???
Thanks in advance.
-J
Is that the only script that calls functions.php?
Instead of logging just "POST FAIL", try logging the result of print_r($_POST, true) and maybe $_SERVER['HTTP_REFERER']. That may tell you where the failed calls are coming from.
Try an HTTP sniffer to first figure out if it's your PHP script with the problem or the AJAX code. Or it could be a client-side condition you're not aware of. It might not be your AJAX code at all. Sniffer will help eliminate whether it's definitely a client-side issue or not.