SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Getting javascript activity to the server

    Suppose I'm allowing a user to customise the page by adding and removing things. So while they're doing this with javascript, the things that are added/removed are shown/hidden by swapping their CSS display property between 'block' and 'none'. But if I want to persist this across all pages they visit, so that when they click on something the server knows to hide this from the start, I'm setting a cookie that the server checks to see whether element X should be shown or not.

    It's the only way other than Ajax I can think of to communicate this stuff silently to the server. Still, it seems kind of dirty to me - is there a better way?

  2. #2
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    The only other way is Ajax, that's what it's made for.
    Saul

  3. #3
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Thought so. Which do you reckon is the better solution, taking absolutely everything you could think of into account?

  4. #4
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hm, let's see...

    You should go with Ajax because...

    ...the app only relies on JS while the other way also relies on cookies. Both can be turned off on the client side.

    ...the app rapidly reacts to the user actions. If the browser is turned off before the page is reloaded, the changes may not be saved. That depends on the cookie settings, of course.

    ...it is easier to make the site more usable and/or accessible. If the JS is turned off, you can use the regular links to the same script that is called asynchronously with Ajax. Same can be done if you used cookies, but I think it is easier with Ajax -- you build Ajax on the regular script (or at least you should), that means no extra work.

    ...there are more possibilities to expand on it.

    ...it makes the site web 2.0 compliant

    But you may go with the cookies because...

    ... I can't think of anything. And I'm a fan of Ajax anyway.

    Edit:


    Well, there is one reason you might wanna use the cookies instead. If the app is very little and it is not very important to save the user settings for a long time. If it's rather cosmetics, you can use the cookies. But Ajax pays off in the long run anyways.
    Saul

  5. #5
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    What you put in the edit box is spot on, it's mostly cosmetic, the app is small and the cookies die at the end of each browser session. Whether the data is saved or not is not crucial at all, just more or less important for it to be saved from page to page (over the course of a session) so as not to annoy the user. I agree that Ajax seems like a nicer solution, at present I'm using JS + cookies and Ajax is just JS, so it just seems less messy.

    Also, I think it's more likely that cookies are off rather than javascript. Ajax it is then, good for my e-go too.

    Cheers for the ideas.

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I did this once using AJAX and it worked great. I stored the shown/hidden state in a database for each user so that there settings would be saved. Only thing is on a large scale site that database could grow quickly especially if there are a lot of things to show/hide.
    Kayzio - We don't hesitate, we accelerate.

  7. #7
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Cool. I figure I won't even need to use a database - just PHP's session handling.

  8. #8
    SitePoint Zealot
    Join Date
    Mar 2007
    Posts
    196
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yea the only reason I used a database was the reason that I wanted to allow the user to save their settings to their account so they could log in on any pc and have things in the state that they set them (makes it a little more personal to the user).
    Kayzio - We don't hesitate, we accelerate.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •