Jump to content

Archived

This topic is now archived and is closed to further replies.

neoaddict

PHPP cookie help

Recommended Posts

[code]<script type="text/javascript">
    function makeRequest(url) {
        var http_request = false;
        if (window.XMLHttpRequest) {
            http_request = new XMLHttpRequest();
        } else if (window.ActiveXObject) {
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e) {}
            }
        }
        if (!http_request) {
            alert('Your browser does not support AJAX or XMLHttpRequest!');
            return false;
        }
        http_request.open('GET', url, true);
        if (url == "checkcookie.php") {
            http_request.onreadystatechange = parse;
        }
        http_request.send(null);
    }

    function parse() {
        if (http_request.readyState == 4) {
            if (http_request.status == 200) {
                var css = http_request.responseText;
                document.getElementById("topsites").style.display = css;
            }
            else{
                alert('There was a problem with the request.');
            }
        }
    }

    open('checkcookie.php');

    function omgmagic() {
        if(document.getElementById("topsites").style.display == 'none'){
           makeRequest('show.php');
           document.getElementById("topsites").style.display = '';
        }
        else{
           makeRequest('hide.php');
           document.getElementById("topsites").style.display = 'none';
        }
    }
</script>

<div style="cursor: pointer;" onclick="omgmagic()">Expand/Collapse Topsites Images[/code]
That's my current code so far - I think I've got all the AJAX right, but I don't know what to put in the PHP files except setcookie, perhaps?

Thanks.

Share this post


Link to post
Share on other sites
What! Whats your question? Not a lot of info is comming from what you have said so fair!
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]That's my current code so far - I think I've got all the AJAX right, but I don't know what to put in the PHP files except setcookie, perhaps?

Thanks.[/quote]

Share this post


Link to post
Share on other sites
Well, I'm trying to make this AJAX script keep persistence for a collapse div script, I think I've got the AJAX all done, but I can't seem to figure out what to put in the PHP files.

checkcookie.php should check if cookies exists, and if so, outputs the value of the cookie to the AJAX script.
hide.php is for the hide cookie
show.php is for the show cookie

Share this post


Link to post
Share on other sites
Does anyone know what I can put in the PHP files?

I'm having problems figuring out what to put in them.

checkcookie.php should check for the cookie, if exists, display div accordingly and set output to script, if not, send do nothing output to script.

Don't know how to send output from a PHP file to an AJAX script.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.