Displaying content with javascript

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
jurriemcflurrie
Forum Commoner
Posts: 61
Joined: Wed Jul 06, 2005 7:14 am
Location: Den Haag, the Netherlands

Displaying content with javascript

Post by jurriemcflurrie »

Hey all,

I fairly new to javascript, and I'm trying to build an AJAX/JSON account script (although I have the same problem with other javascript attempts).

Let's say I have 3 pages. A Login, Create and a Welcome screen. When the client is not logged in, the Login screen should come up when the page loads. Otherwise, the welcome screen is shown.

What should I do:

Parse the screen that I need and get other screens behind the scenes (default prototype.js behaviour?) - this is not what I want 'couse I think this can be done much nicer.

Parse all screens on one page and hide the ones I don't need with javascript, and switch between those? This means that users with javascript disabled end up with a messed up screen, and when people view the source they see content they shouldn't.

Generate the screens with javascript. When I would do this, I'd have two versions of the same screen. One in javascript, one parsed by PHP so that the client won't have to wait till the page has loaded.

Or does anyone have a better solution?

Thanks in advance!
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

If you are using Ajax then I assume you are also using PHP. Use PHP and sessions (or database) to maintain whether the user has been authenticated and has access to a specific page.
(#10850)
User avatar
jurriemcflurrie
Forum Commoner
Posts: 61
Joined: Wed Jul 06, 2005 7:14 am
Location: Den Haag, the Netherlands

Post by jurriemcflurrie »

My question wasn't about how to handle user authentication / authorization at all ;)

[edit]
If the response contains a JSON object 'messages', something went wrong and the messages are displayed above the inputs. If it contains an 'user' object, login is succesful and the welcome screen should pop up.

When a user comes back tomorrow (it will be remembered), the welcome screen should be shown. It makes no sense to make another request to the server to check if the user is logged in or not, it should be parsed this way on the first request.

So I end up with a welcome screen in my template and another in javascript, which I both have to change if I want another welcome screen.
Post Reply