Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Handling too many ajax requests

 
Dhaval J. Patel
Ranch Hand
Posts: 90
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I am working on a booking system right now. On one of the pages I have a list of checkboxes that represents one item that you can book. So everytime you click on that checkbox an ajax request is sent to the server which would return the updated cost. My boss said that this is an absolute requirement to update the cost each time the user clicks on a checkbox.

I am thinking that everytime a user clicks, an ajax request would come in, wouldnt it degrade the performance of my webpage if a user keeps on clicking. Is there any way to address this issue? Some kind of mechanism that would hold the ajax request till the user stops clicking and then I could send the request.

I thought of putting a timer in javascript to some interval before a request is sent, but that wouldnt work as the user would have to wait for the timer to finish before he can click the next checkbox ( if only I could run multiple threads in javascript, but that would get too complicated)

Any Help would be appreciated,

Thanks in advance
 
Paul Clapham
Sheriff
Pie
Posts: 20959
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So to summarize: you don't know if there is a problem, but your only "solution" has the side effect of annoying the user. Which of course you don't want to do.

And really, how fast can your users click anyway? I suggest you are suffering from "Premature Optimization" (you could look it up). Don't solve problems until you know they exist.
 
Stefan Evans
Bartender
Posts: 1691
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What are the chances of turning the ajax call into a local javascript one?
If you check/uncheck this checkbox, the price goes up/down by $x.
 
Paul Clapham
Sheriff
Pie
Posts: 20959
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also, AJAX is asynchronous (that's what the first A stands for) so there shouldn't be any problem with two submitted requests overlapping. Unless you did something careless and made your servlet not be thread-safe, that is. And: is the response time for calculating the updated code annoyingly slow? If that's the case you might find the users clicking the same checkbox twice because they aren't seeing the result in a timely fashion. But basically, as I said, that shouldn't be a problem.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic