Search code examples
phpjavascripthttpblock

Block same request from same server session


This is not really a question to resolve a problem. All i want is to find out the common way of doing blocking same type of http request from the same user.

Why i need this:

When a user clicks on a button, an Ajax request goes off, and returns a result through append();
If the user clicks on the button twise (and if he does it fast),
results that are fetched from database get screwed up, which is not good. BUT, if the user clicks on the button AFTER the first request got COMPLETELY processed, the returned results are good!

What i think i could do:

1) I could do it through .js (by switching id or disabling buttons)
2) I could do that through php (i am sure there is a set of functions for that)
3) Or do that throguh the server settings (but i know almost nothing about those!)

So, what would be the best way to block second http request from same user untill the first request is processed?

Thanks!


Solution

  • Just disable the button or set a flag that switches back on after your callback is executed.

    There is no need to overcomplicate PHP or mess around with the server (not sure what you mean by this though).