views:

43

answers:

2

I have a table/grid system with a 7 days along the top and the various types of data down the side, now for each type of data against a particular day there's a plus and minus sign so the user can increase or decrease the data occurrences. Now given that there's plenty of data types as well as 7 (for each day) values for each type, what's the best way to do it in everyone's opinion? I'm dubious about ajax as each plus and minus click would call a db operation, but the only other alternative (please correct me if I'm wrong) is that i dynamically update the values of a form and then force the user to "submit" once they've submitted all the info they need - but this is a lot of form values to process?

Cheers,

A: 

You could possibly use Ajax once the user leaves the page.

$(window).unload(function() {
  // Create json object
  var json = {...}

  $.post('/reciever.php', json);
});

But I would suggest that you update in realtime even though it means a bunch of db-calls. It shouldn't be to expensive.

Christoffer
A: 

To send a form, it's better you use jQuery form plugins.

For a best practise advice:

  1. Create your page and make it work without javascript enabled (without ajax).
  2. Add a javascript(jQuery) code to enhance user's experience by sending only data and load the response using AJAX, then update the portion of the page.
  3. Review your code to find out which section that can be optimized to reduce db operation. You can optimize your algorithm or using cache. Either way, this is done after you get enough data and user's action so you know which code that called often and where is the bottleneck in your application.
Donny Kurnia