Welcome Guest, Not a member yet? Register   Sign In
Work differentiation between CodeIgniter / jQuery - best practice
#1

[eluser]AndyBC[/eluser]
Hi guys!

A newbie architectural question:

I am looking for some guidance on 'best practice' in apps where you need the browser (javascript) and the server (codeigniter) to handle the same elements on a page.



Example:

1) Say you on the server side generates a 'select widget' with selectable items (just think <ul> with lots of elements)

2) In the browser, when user clicks an item, you'll have jquery add a special style to that item, to indicate it's selected.

3) When the user clicks 'submit', you post information about which items is selected to the server.

4) On the server Codeigniter does something with that information and returns a NEW page (so this is not done with ajax, but requires a page refresh).


So far no problem - This is what I'm not sure about:

On the returned page I need to redisplay the 'select widget', with the previously selected items being in the visual selected state.

* I could easily have php/Codeigniter do the SAME thing as jquery to the selected elements - i.e. apply the 'selected style' to them. But that would duplicate function between Codeigniter and jquery - so now I have two places to update when I need to change anything.

* So I was thinking that I could have CI do the vanilla 'select widget' plus a javascript array with the selected items and then let the jquery function take care of the special 'selected' formatting for those items, when the page loads.

-

I expect the exact same question on how to differentiate between server / browser control of the UI would pop up with other parts of the apps (error messages in forms, etc..) So is there a general best practice solution to this (or am I thinking about this in a wrong way - remember I am newbie)

Thanks for taking your time :-)

AndyBC


Messages In This Thread
Work differentiation between CodeIgniter / jQuery - best practice - by El Forum - 08-02-2010, 06:56 AM



Theme © iAndrew 2016 - Forum software by © MyBB