本文介绍了快速的onkeyup问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 网址: http://events.unl.edu/ 描述:我为日历编码了一个快速而又脏的键导航。 如果你按下键盘上的左箭头,它将导航到 之前的日期并触发ajax请求以获取内容。反之亦然 为右箭头键。 问题:问题是你多次点击箭头键几次 连续(我的测试人员中有4/5这样做可以快速达到他们想要的具体的 日期),ajax请求调用无法继续。我想到了几个可能的解决方案,但没有一个是稳固的,并没有真正做到我想要的b $ b。其中包括在keyup上附加超时(这意味着即使 ,当用户没有连续多次录音时,他们必须等待, 说ajax开火前2秒打电话。) 我真的很感激任何关于此的建议和想法。 提前致谢。 解决方案 我知道大多数浏览器允许最多2个同时 XMLHttpRequests。 (用户可以增加这个,但是你不能依赖它。)所以,你有几种不同的模型 可以试试这个。首先,根据您的可用 带宽,您可能希望每个请求检索不止一个keytap'的价值 数据。对于日历应用程序,根据您的实施和您获得的数据,这不应该超过每月500亿美元。将此缓存保存在一个跨越6个月的数组中,在当前查看日期的任何一侧 ,并在3-6个月内检索信息块以保持领先于用户。 此外,您可以在队列中拥有按键请求的缓冲区。将一个 按键请求推送到一个数组上,然后让你的Ajax方法将 前一个请求从队列中移开,只要它已经准备好并完成最后一个 请求。这不一定会加快用户体验的速度,但至少 将记录所有击键并获得响应。这里将涉及一定数量的用户培训,因为一个不耐烦的用户将会很快发现在Ajax请求时敲击密钥20次 待定不会让它更快发生。所以用户的反馈将是必要的 - 并且我认为在忙碌的时候也会冻结控件(有一些 视觉提示一个沙漏)(这应该只是几次击键后发生 )。所以你可以通过询问你的Ajax处理程序对象是否有任何 请求免费来忽略你的 击键处理程序中的新击键。 只是一些高层次的想法。如果您有特定于实现的 问题,请随时询问。 David David Golightly写道: 那是不完全正确。 Internet Explorer(但不是Firefox)不允许 同时在 打开任何类型的两个同时请求(IO流)。假设您可以打开< http://www.cnn.comand 同时从< http://www.google.comat下载文件。对于 任何第三个连接IE填充必须使用其内部流管理 这样快速切换消费者:这就是为什么你可以同时 打开甚至20页:但是这种同时性与在页面上移动的20个元素相同:当时只有一个元素 正在移动,但延迟时间太短而无法看到它。 顺便说一下这就是为什么像Comet这样的东西对于IE来说是一个真正的杀手:它强制执行 来保持打开两个唯一的通道中的一个,从而打破内部 流优化。 此仅限两个频道对于任何免费的IE 版本(可以从microsoft.com下载)都可以实施限制。对于Windows NT (取决于您支付的许可)此限制为5或10 同步流 - 包含额外IE功能的价格 进入操作系统许可证。 如果有人的眼睛看到上面那么大的话,那么就去获得一些冷水吧 - 下次在点击I 接受之前阅读这些内容:-) 这与OP问题无关。 XMLHttpRequests。 (用户可以增加这个,但是你不能依赖它。)所以,你有几种不同的模型 可以试试这个。首先,根据您的可用 带宽,您可能希望每个请求检索不止一个keytap'的价值 数据。对于日历应用程序,根据您的实施和您获得的数据,这不应该超过每月500亿美元。将此缓存保存在一个跨越6个月的数组中,在当前查看日期的任何一侧 ,并在3-6个月内检索信息块以保持领先于用户。 此外,您可以在队列中拥有按键请求的缓冲区。将一个 按键请求推送到一个数组上,然后让你的Ajax方法将 前一个请求从队列中移开,只要它已经准备好并完成最后一个 请求。这不一定会加快用户体验的速度,但至少 将记录所有击键并获得响应。这里将涉及一定数量的用户培训,因为一个不耐烦的用户将会很快发现在Ajax请求时敲击密钥20次 待定不会让它更快发生。所以用户的反馈将是必要的 - 并且我认为在忙碌的时候也会冻结控件(有一些 视觉提示一个沙漏)(这应该只是几次击键后发生 )。所以你可以通过询问你的Ajax处理程序对象是否有任何 请求免费来忽略你的 击键处理程序中的新击键。 只是一些高层次的想法。如果您有特定于实现的 问题,请随时询问。 David 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 theprevious date and fire an ajax request to grab the content. Vice versafor right arrow key.Problem: the problem is when you multi-tap the arrow key a few timesconsecutively (4/5 of my testers do that to quickly get to the specificdate they want), the ajax request call cant keep it up. I thought of afew possible solution but none of them were solid and didn''t really dowhat i want. Among those is attaching timeout on keyup (that means evenwhen 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. 解决方案I understand that most browsers allow a max of 2 simultaneousXMLHttpRequests. (It''s possible for the user to increase this, but youcan''t rely on that.) So, there are a couple of different models youcan try for this. For one thing, depending on your availablebandwidth, you may wish to retrieve more than just one keytap''s worthof data per request. For a calendar application, depending on yourimplementation and what data you''ve got, this shouldn''t be more than a500B per month. Keep this cached in an array that spans 6 months oneither side of the currently viewed date and retrieve info in 3-6 monthchunks to keep ahead of the user.Also, you can have a buffer of keypress requests as in a queue. Push akeypress request onto an array, then have your Ajax method shift thefront one off the queue whenever it''s ready and finished with the lastrequest. This won''t necessarily speed up the UX too much, but at leastall keystrokes will be recorded and get a response. There will be acertain amount of user training involved here as an impatient user willquickly find that tapping the key 20 times while the Ajax request ispending will not make it happen faster. So user feedback will benecessary - and I would think also freezing the control (with somevisual cue a la hourglass) when it''s busy (which should only happenafter several keystrokes). So you can ignore new keystrokes in yourkeystroke handler by asking your Ajax handler object if it has anyrequests free.Just some high-level thoughts. If you have implementation-specificquestions feel free to ask.DavidThat is not exactly true. Internet Explorer (but not Firefox) allows nomore than two simultaneous requests (IO streams) of any kind open atthe same time. Say you can be opening <http://www.cnn.comanddownloading a file from <http://www.google.comat the same time. Forany third connection IE fill have to use its internal stream managementso quickly switching consumers: this is why you can "simultaneously"open even 20 pages: but this "simultaneousity" is of the same kind as20 element moving on the page over script: really only one at the timeis moving, but the delay is too short to see it.btw this is why stuff like Comet is a real killer for IE: it enforcesto keep open one of two only channels and so breaks the internalstreams optimization.This "two channels only" limitation is enforced for any free IEversion (one you can download from microsoft.com). For Windows NT(depending on license you paid for) this limit either 5 or 10simultaneous streams - the price for extra IE capabilities is includedinto OS license.If anyone''s eyes got big and round of reading the above then go getsome cold water - and next time read the stuff before clicking "IAccept" :-)It is pretty irrelevant to the OP problem though.XMLHttpRequests. (It''s possible for the user to increase this, but youcan''t rely on that.) So, there are a couple of different models youcan try for this. For one thing, depending on your availablebandwidth, you may wish to retrieve more than just one keytap''s worthof data per request. For a calendar application, depending on yourimplementation and what data you''ve got, this shouldn''t be more than a500B per month. Keep this cached in an array that spans 6 months oneither side of the currently viewed date and retrieve info in 3-6 monthchunks to keep ahead of the user.Also, you can have a buffer of keypress requests as in a queue. Push akeypress request onto an array, then have your Ajax method shift thefront one off the queue whenever it''s ready and finished with the lastrequest. This won''t necessarily speed up the UX too much, but at leastall keystrokes will be recorded and get a response. There will be acertain amount of user training involved here as an impatient user willquickly find that tapping the key 20 times while the Ajax request ispending will not make it happen faster. So user feedback will benecessary - and I would think also freezing the control (with somevisual cue a la hourglass) when it''s busy (which should only happenafter several keystrokes). So you can ignore new keystrokes in yourkeystroke handler by asking your Ajax handler object if it has anyrequests free.Just some high-level thoughts. If you have implementation-specificquestions feel free to ask.David 这篇关于快速的onkeyup问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
07-22 18:22
查看更多