POST Fail via AJAX Request?

Posted by Jascha on Server Fault See other posts from Server Fault or by Jascha
Published on 2010-05-19T20:55:35Z Indexed on 2010/05/19 21:02 UTC
Read the original article Hit count: 466

Filed under:
|
|

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:

alt text

if it were NOT being skipped, my data would show up like this:

alt text

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

© Server Fault or respective owner

Related posts about php

Related posts about AJAX