当我发送请求时,Keyup 会影响浏览器中文本框中的输入。这有可能阻止影响吗?
在网页中,我有一个文本框,用户可以在其中输入内容并通过ajax请求响应更改内容来获取结果。
因为如果我打字速度更快,那么响应可能会晚于打字,所以打字速度会变慢。
这有可能阻止此类问题的影响吗?
in a webpage i have a textbox where user type something and get the result as change the content through ajax request response.
because if i type faster then response maybe late then typing so it' make typing speed slow.
are this possible to stop affect these kind of problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了防止这种情况,我通常会这样做:
它在最后一次按键后等待 200 毫秒,然后再发出请求,如果发生新的按键,则重置超时。
to guard against this i usually do something like:
it waits 200 milliseconds after the last keyup before making the request, if a new keyup occurs the timeout is reset.
一旦您在文本框中输入内容,您的 AJAX 请求就会启动。锁定或禁用文本框以防止键入。一旦 AJAX 请求从服务器返回,您的回调函数应该重新启用文本框。这将确保输入永远不会“领先于”AJAX 响应。
为了处理得很好,您可以在锁定的文本框上显示动画。
As soon as you type something in your textbox your AJAX request will fire off. Lock or disable the textbox to prevent typing. Once the AJAX request comes back from the server your callback function should re-enable the textbox. This will ensure that the typing never gets "ahead" of the AJAX responses.
For handling niceness you would show an animation over the locked textbox.