1''''
1''''

Reputation: 205

PHP / Ajax / jQuery data submission approach

I have a table/grid system with seven days along the top and the various types of data down the side. 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. Given that there are plenty of data types as well as seven (for each day) values for each type, what's the best way to do it?

I'm dubious about Ajax as each plus and minus click would call a database 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 information they need - but isn't this a lot of form values to process?

Upvotes: 0

Views: 154

Answers (2)

Donny Kurnia
Donny Kurnia

Reputation: 5313

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

For a best practice advice:

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

Upvotes: 0

Christoffer
Christoffer

Reputation: 26835

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.

Upvotes: 1

Related Questions