Hi,
I've been thinking about how I can create a poll that allows users to submit new entries and vote up existing entries. The poll would then update periodically, adding any new entries (that other users may be adding), updating votes for each entry and then resorting all entries by decreasing votes - all through ajax.
Some areas I'm seeking advice in this implementation:
- I'm thinking of using XML data type instead of JSON, since it allows structured data to be better presented (although larger data transfer leading to higher bandwidth costs)
- Should the server-side script return all the data from this poll, and let the client-side script (i'm looking at jQuery plugin PeriodicUpdater script atm) determine if there's a change in data, Or should I programme the server-side script to return only the new entries? If the server-side script returns only the new entries, I'm thinking i'll need to add a timestamp to each ajax call but am unsure PeriodicUpdater script allows that. Second, that would mean I'll not be able to fetch the most updated vote count for existing entries.
If each ajax poll returns the full data set, I'm thinking that I would parse each entry and check if it exists (using .length() on the dom element), if it exists, i'll check if the vote count is the same, else, update. If the entry does not exist, i'll prepend to the top of the list (although it shouldn't matter since it's going to be sorted after this update). Finally, I'll then send the update call to tablesorter.
I'm not sure if the above is too resource-intensive, or whether it's a case of bad programming/methodology. Is there another way I should do this?
I want to use ajax since this would mean the user would be less interrupted (as opposed to a page refresh), the experience would be more seamless and the whole polling affair would be quite "live". However, i'm not sure if the implementation I mentioned earlier, that the visual disturbance from each update, would be almost akin to a page refresh. Any thoughts? Ideally, it would be nice to have some animations to move existing entries up/down etc. But I've no absolute clue how to do that. Haha.
I'm currently thinking of using jQuery plugins PeriodicUpdater and tablesorter, with my data created with 2 columns (votes and entries). Are there any other plugins (ajax server polling and sorting of data) that can do this better?
Any advice is greatly appreciated. Sincere thanks :) -Lyon