在等待ajax更新时禁用jquery可排序的方法?
我有一个 jquery 可排序的,带有与更新事件相关的 ajax 回调。 ajax 回调将更新的排序顺序发送回服务器,然后刷新可排序以保证客户端和服务器同步。
我遇到的问题是用户可以在 ajax 调用完成之前启动一个新的可排序事件 - 我想防止这种情况发生。
我尝试做的是在更新事件上禁用可排序,然后在 ajax 调用返回时重新启用它。但是,除非我弄乱了顺序,否则这似乎不起作用 - 当 ajax 调用仍然处于活动状态时,我仍然可以启动新的可排序拖动。
还有其他方法可以防止这种情况吗?我当然可以设置一个全局 javascript 变量,表示“嘿,现在不行,我正在 ajax...”并引用它,但我不确定哪个可排序事件会对此进行检查,或者它将如何杀死可排序单击请求。
想法?
I have a jquery sortable with an ajax callback tied to the update event. The ajax callback sends the updated sort order back to the server and then does a refresh of the sortable to guarantee that the client and server are both in sync.
The problem I am having is that the user can start a new sortable event before the ajax call has completed - I'd like to prevent that.
What I did try doing was disabling the sortable on the update event, and then re-enabling it when the ajax call returned. However unless I messed up the sequence, this didn't seem to work - I can still start a new sortable drag while the ajax call is still active.
Is there any other way to prevent this? I can certainly set a global javascript variable that says, "hey not right now, I'm ajaxing..." and reference it, but I'm not sure what sortable event would check for this, or how it would kill the sortable click request.
Thoughts?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
为了更好的用户体验...
您应该取消之前的ajax请求,而不是禁用该界面,这样它就不会覆盖任何新请求。
这使界面保持响应灵敏、流畅且灵活。
它允许用户在等待保存时“改变主意”并重新排序列表。
任何旧请求都会被取消,因此不会覆盖新请求...
For a better user experience...
Instead of disabling the interface, you should cancel the previous ajax request so that it doesn't overwrite any new requests.
This keeps the interface responsive, fluid and flexible.
It allows the user to 'change their mind' and reorder the list while waiting for it to save.
Any old requests are cancelled and therefore don't overwrite new requests...
您可以简单地在整个列表上覆盖一个透明的绝对定位的 div,这将防止列表上的任何点击/拖动。
在 CSS 中将其设置为
display: none
。然后,当您发起 AJAX 调用时,将其设置为display: block
,并在 AJAX 调用完成时将其切换回display: none
。You can simply overlay a transparent absolutely-positioned div over the whole list, which will prevent any clicks/drags on the list.
Set it in your CSS to
display: none
. Then, when you initiate an AJAX call, set it todisplay: block
, and when your AJAX call completes, switch it back todisplay: none
.您是否尝试设置禁用属性?
然后在ajax请求之后
Did you try to set the disabled property ?
And then after the ajax request