简体   繁体   中英

AJAX Caching issue

Ok a lot of answered articles about this have been dealing with POST and whatnot, but this is for none of those reasons.

I do realize I could use the .load() function which I have and it still caches it that way. It said through AJAX, they had a cache attribute you could set to false so I switched methods. However, they both result the same...

        $.ajax({
                url: "<?= $GLOBALS['SECURE_AREA']."inline/login_status.php?call_letters=$GLOBALS[call_letters]&t=".rand(100,999)."" ?>",
                cache: false,
                success: function (data) {
                    $("#user_info").html(data);
                }
        });
        //$("#user_info").load("<?= $GLOBALS['SECURE_AREA']."inline/login_status.php" ?>");

The url does exist. When I go to it, it displays the results correctly that I want. However this is still displaying the very first load it gave.. and not refreshing since after you login, the content changes.. It's still saying "Signup | Login".. Not "My Account"

Any idea on how to fix this? The AJAX and .load() method both do not work for me. They both cache.

I can offer an alternative -

With PHP, you can echo the data you need directly into the page... for example

<?php echo <<<JS
    $.ajax({
        url: "\"".$GLOBALS['SECURE_AREA'] . "inline/login_status.php?call_letters=".$GLOBALS['call_letters']."&t=".time()."\"", // per @phpissuper01
        cache: false,
        success: function (data) {
            $("#user_info").html(data);
        }
    });
JS;
?>

What this will do will execute your ajax when this is placed in, and since only PHP can access the $GLOBALS var, you can echo out what you need.

Furthermore, You have several issues with string concatenation in your code which contributed to the errors, which are fixed in this answer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM