views:

21

answers:

2

For instance adding new categories to a list.

Once a new category has been added, and successfully submitted to the db, should I use JS to directly append this value to the list or should I query the table again and repopulate the list?

A: 

It depends on how many users will be using you system/application. If the concurrency level is too high and it is expected that there will be frequent addition of categories, then you would probably want to query the db to get the whole list and display it, but if this is not the case, then it should be OK to just append the present entry to the list.

Mahesh Velaga
A: 

You can do both. What's easiest will depend on what needs to be done to show the new category in the list. If it's simply adding the category name to the list, there's no need to reload the list. If you need to add it somewhere in between to maintain alphabetic order, it gets trickier. If adding a category means that many other elements are influenced by that and need to change as well, reloading the full list might be easier.

One disadvantage of reloading the full list is the possibility of duplicate code. You need the list plus markup the first time when you load the page and generate the HTML with PHP, and a second time when you reload the list using JavaScript. In such cases it's best to setup your scripts in a way that you can easily use the same code to request this list. Otherwise you'll be writing the same thing twice.

Alec
thanks they are some good points to think about. I may now actually repopulate the list, as keeping everything in alphabetic order would be better for UX rather than index number which I have currently been working with - I would also think this would be the safer option, as there is less chance of errors occurring between the value and index number.
davivid