tags:

views:

81

answers:

3

I can't for the life of me figure out why this is happening.

This is kind of a repost, so forgive me, but I have new data.

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

A: 

Try enabling error reporting on the jquery $.ajax function, your code would look something like

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');
        },
       error: function(XMLHttpRequest, textStatus, errorThrown) {
       alert(textStatus+" - "+errorThrown);
       }
    });
}

See if that sheds light on your situation.

Obsidian
@obsidian thank you for that.. but I just figured it out, it's because of the "http://www.mydomain.com/function.php" not reading locally. For some reason, AJAX thinks this is a cross site call every couple of hours... Definitely a server issue.
Jascha
A: 

I have a strong feeling that it's more of a server side issue rather than the client's.

The odd thing is that you see the problem for a period of time. If the client works at all, then at the minimum refreshing the page or restarting the browser should fix it.

The die() at the end of the function is suspicious, but I am not quite sure how it will affect it.

Btw you can see http headers in FireBug's Net tab, to know whether those parameters has been sent properly.

coolnalu
@coolnalu, I just figured it out and posted the answer. Thank you for inputting on this. I had to throw the die() command in there to make sure my script doesn't keep running and post the "POST FAIL" to the database at the end of the script.
Jascha
+3  A: 

Ok, for those interested.

I removed the full URL http://www.mydomain.com/functions.php and replaced it with the local path functions.php and that did the trick.

Apparently AJAX has issues with cross domain ajax calls and I'm not on a dedicated server, so I imagine what's happening is every couple hours (or minutes) I am somehow hitting my script from a different location causing AJAX to dismiss the POST data.

-J

Jascha
Could you mark your answer as the correct one and close off this question? Just so people don't think you are still having dramas...
Lucanos
@Lucanos, I'd love to. But, stackoverflow says I have to wait 2 days to accept my own answer.
Jascha
Fair enough (I had heard there was a restriction, but I wasn't sure the details).
Lucanos