双击有多快?
我有以下 JS 代码
$('#dialog').dialog({
...
buttons: {
OK: function() {
callAjax({"some":"param"});
$('#dialog').dialog('close');
}
}
});
var ajaxBatch = [];
function callAjax(cmd) {
ajaxBatch.push(cmd);
if (ajaxBatch.length == 1)
setTimeout(ajaxItself, 1);
}
function ajaxItself() {
ajaxBatch.push({"minor":"data"});
$.post('url', { msg: JSON.stringify(ajaxBatch) });
ajaxBatch = [];
}
理论上我应该总是得到 [{"some":"param"},{"minor":"data"}]
。
但我经常收到关于 [{"some":"param"},{"some":"param"},{"minor":"data"}]
错误请求的错误日志条目。
怎么会发生这样的事情呢?带 2x 按钮的 A4 鼠标在这里有意义吗?
顺便说一句,我无法重现这种情况,我只是在日志中看到它。用户代理也不限于特定的浏览器。
I have the following JS code
$('#dialog').dialog({
...
buttons: {
OK: function() {
callAjax({"some":"param"});
$('#dialog').dialog('close');
}
}
});
var ajaxBatch = [];
function callAjax(cmd) {
ajaxBatch.push(cmd);
if (ajaxBatch.length == 1)
setTimeout(ajaxItself, 1);
}
function ajaxItself() {
ajaxBatch.push({"minor":"data"});
$.post('url', { msg: JSON.stringify(ajaxBatch) });
ajaxBatch = [];
}
Theoretically I should always got [{"some":"param"},{"minor":"data"}]
.
But frequently I got error log entries on wrong requests with [{"some":"param"},{"some":"param"},{"minor":"data"}]
there.
How such things may happen? Do the A4 mice with their 2x button make sense here, or what?
BTW, I can't reproduce the situation, I just see it in logs. And User-Agent is not bounded to particular browser there either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
浏览器可能已将超过 1 个单击事件排队,因此无论按钮是否可见以供他们继续单击,事件都已启动。
也许在您的
OK:
函数中设置一个标志我想浏览器会选择处理事件队列中的项目而不是处理 setTimeout 队列中的项目。
The browser might have queued up more than 1 click event, so whether or not the button is visible for them to keep clicking, the events were already set in motion.
Maybe set a flag in your
OK:
functionI would imagine a browser would choose processing an item from the event queue over processing an item from the setTimeout queue.