quick onkeyup problem

A

alvinwoon

URL: http://events.unl.edu/

Description: i coded a quick and dirty key navigation for the calendar.
if you press left arrow on your keyboard, it will navigate to the
previous date and fire an ajax request to grab the content. Vice versa
for right arrow key.

Problem: the problem is when you multi-tap the arrow key a few times
consecutively (4/5 of my testers do that to quickly get to the specific
date they want), the ajax request call cant keep it up. I thought of a
few possible solution but none of them were solid and didn't really do
what i want. Among those is attaching timeout on keyup (that means even
when users are not multi-taping consecutively, they have to wait for,
say 2 seconds before the ajax fires the call.)

I would really appreciate any advise and ideas regarding this.

Thanks in advance.
 
V

VK

David said:
I understand that most browsers allow a max of 2 simultaneous
XMLHttpRequests. (It's possible for the user to increase this, but you
can't rely on that.)

That is not exactly true. Internet Explorer (but not Firefox) allows no
more than two simultaneous requests (IO streams) of any kind open at
the same time. Say you can be opening <http://www.cnn.com> and
downloading a file from <http://www.google.com> at the same time. For
any third connection IE fill have to use its internal stream management
so quickly switching consumers: this is why you can "simultaneously"
open even 20 pages: but this "simultaneousity" is of the same kind as
20 element moving on the page over script: really only one at the time
is moving, but the delay is too short to see it.
btw this is why stuff like Comet is a real killer for IE: it enforces
to keep open one of two only channels and so breaks the internal
streams optimization.

This "two channels only" limitation is enforced for any free IE
version (one you can download from microsoft.com). For Windows NT
(depending on license you paid for) this limit either 5 or 10
simultaneous streams - the price for extra IE capabilities is included
into OS license.

If anyone's eyes got big and round of reading the above then go get
some cold water - and next time read the stuff before clicking "I
Accept" :)

It is pretty irrelevant to the OP problem though.
 
A

alvinwoon

Thanks for the quick reply. High level thoughts are actually what i am
looking for.

Maybe i didnt explain the problem well enough (english is my 2nd
language). The dilemma here is not so much on the speed or bandwidth;
it's more towards finding a way to deliver accurate information.

Ok, let's try this again:

Visit: http://events.unl.edu
Let's assume the user is currently on 29th Nov (today). To get back to
25th Nov, he can press on the left arrow key for 4 times. Everything is
good if he doesnt press it too quickly. But if he does, the selector
will stops at 25th just fine but since the ajax call cant keep up with
the key event listener, the content loaded on the right hand side would
most likely be events prior to 25th (i am guessing 23rd if you press
real quick).

Nevertheless, i think your array solution is worth a try.
Theoretically, i can see how it might works. I will let you know.

More ideas?
 
V

VK

Problem: the problem is when you multi-tap the arrow key a few times
consecutively (4/5 of my testers do that to quickly get to the specific
date they want), the ajax request call cant keep it up. I thought of a
few possible solution but none of them were solid and didn't really do
what i want. Among those is attaching timeout on keyup (that means even
when users are not multi-taping consecutively, they have to wait for,
say 2 seconds before the ajax fires the call.)

I would really appreciate any advise and ideas regarding this.

You idea with delay is the right one: but 2sec maybe is too long, 1sec
is enough (?)

var timerID = null;

formControl.onkeyup = function() {
if (timerID != null) {
window.clearTimeout(timerID);
}
timerID = window.setTimeout(MyAJAXRequest, 1000);
}

This way all timed request will be cancelled until it will be a pause
in keystrokes at least 1sec long
 
R

RobG

David Golightly wrote:
[...]
Also, you can have a buffer of keypress requests as in a queue. Push a
keypress request onto an array, then have your Ajax method shift the
front one off the queue whenever it's ready and finished with the last
request.

Or maybe when each request returns, grab only the last request in the
queue and get that, delete anything else. That way you don't issue
requests for key presses that are just navigation.

To the OP: in Firefox cursor key presses don't change the selected
date.
 
A

alvinwoon

David Golightly wrote:[...]
Also, you can have a buffer of keypress requests as in a queue. Push a
keypress request onto an array, then have your Ajax method shift the
front one off the queue whenever it's ready and finished with the last
request.Or maybe when each request returns, grab only the last request in the
queue and get that, delete anything else. That way you don't issue
requests for key presses that are just navigation.

To the OP: in Firefox cursor key presses don't change the selected
date.

Yeah, i will definitely try the array solution tomorrow. The XHR
library i'm using also has a quick kill off function. Never thought
that could be useful :). Quick question - what is a cursor key presses?

To VK: that would be my last resort - using timeout. Thanks though.
 
M

Matt Kruse

VK said:
That is not exactly true. Internet Explorer (but not Firefox) allows
no more than two simultaneous requests (IO streams) of any kind open
at the same time.

That's absolutely not true.

By hacking the registry, I can successfully make 8 connections to any web
site, simultaneously, using IE6. (That just happens to be what my settings
is, I'm not sure what, if any, limit there is.)

I've often downloaded 5-10 huge files at the same, clearly demonstrating
that your statements are false.
 
A

alvinwoon

By hacking the registry, I can successfully make 8 connections to any web
site, simultaneously, using IE6. (That just happens to be what my settings
is, I'm not sure what, if any, limit there is.)

I've often downloaded 5-10 huge files at the same, clearly demonstrating
that your statements are false.

Ok Let's get done with the high level talk and dive into the
implementation - I cant get the codes to work consistently. How am I
supposed to check whether it is time to fire last request in the array.
How do we catch the flag when people stop pressing the key?

Btw, timeout works fine but...
 
V

VK

Ok Let's get done with the high level talk and dive into the
implementation - I cant get the codes to work consistently. How am I
supposed to check whether it is time to fire last request in the array.
How do we catch the flag when people stop pressing the key?

I posted the proposed workaround right together with my "OT
revelations". Can you see it in this thread? Do you have any problems
remained?
 
A

alvinwoon

revelations". Can you see it in this thread? Do you have any problems
remained

VK - i am not seeing your proposed workaround in this thread. But i'm
new to google groups. Is there somewhere i should be clicking on your
message to view the hidden codes? :)

DG - *alvin is coding using your proposed solution*
 
A

alvinwoon

new to google groups. Is there somewhere i should be clicking on your
message to view the hidden codes? :)

DG - *alvin is coding using your proposed solution*

I solved the problem guys. I just want to say thank you for all the
tips and help. I used a combination of timeout and restructuring the
function call to get the result. Couldnt really get the array push
thing working :(.

If you're interested, you can visit my local build -
http://yansmac.unl.edu/events/
The patch should be applied to the live site any minutes now.

thanks again.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,149
Latest member
Vinay Kumar Nevatia0
Top