jQuery 阻止 UI 异常
我正在使用 JQuery UI 插件 blockUI 来阻止每个 ajax 请求的 UI。它的工作原理就像一个魅力,但是,当我进行 ajax 调用以获取自动完成建议项目时,我不想阻止 UI(或者至少不显示“请稍候”消息)。我该怎么做?我正在使用 jquery 自动完成插件来实现自动完成功能。
有没有办法告诉阻止 UI 插件不阻止 UI 进行自动完成?
I am using JQuery UI plugin blockUI to block UI for every ajax request. It works like a charm, however, I don't want to block the UI (Or at least not show the "Please wait" message) when I am making ajax calls to fetch autocomplete suggest items. How do I do that? I am using jquery autocomplete plugin for autocomplete functionality.
Is there a way I can tell the block UI plug-in to not block UI for autocomplete?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
嗯,看起来 jquery 中缺少一个功能:)
您可以使用全局标志来指示它是否是自动完成调用并将其包装在通用的自动完成函数中
这不是一个很好的解决方案,但它应该可以工作......
Hm, looks to be a missing feature in jquery :)
You could use a global flag to indicate if it is a autocomplete call and wrap it in a general autcompletefunction
It's not a nice solution but it should work...
尝试使用装饰器
,或者您可以编写自己的更智能的块函数
try using a decorator
or you can write your own block function that is smarter
您可以通过添加到全局 jQuery 事件处理程序来将 blockUI 设置为适用于页面上的所有功能。为了确保它不会在自动完成 ajax 调用中被调用,我们必须确定该调用是否是自动完成调用。问题是这些全局函数没有那么多可用的信息。然而 ajaxSend 确实得到了一些信息。它获取用于进行 ajax 调用的设置对象。设置对象具有正在发送的数据字符串。因此,您可以做的是附加到页面上每个 ajax 请求中的每个数据字符串,例如:
例如:
然后我们可以将此代码放在您的文档准备部分中,然后再进行其他操作:
当然,另一个更好的想法是寻找自动完成请求中有些独特的东西,例如 url,但这取决于您正在使用的自动完成插件以及如何使用它。
You can set blockUI to work for all functions on the page by adding to a global jQuery event handler. To make sure it doesn't get called on autocomplete ajax calls we have to determine if the call is an autocomplete call or not. The problem is that these global functions don't have that much information available to them. However ajaxSend does get some information. It gets the settings object used to make the ajax call. the settings object has the data string being sent. Therefore what you can do is append to every data string in every ajax request on your page something like:
For example:
Then we can put this code in your document ready section before anything else:
Of course the other better idea would be to look for something unique in the auto complete requests, like the url, but that depends on which autocomplete plug-in you are using and how you are using it.
使用模态块(块 UI)意味着阻止用户的任何输入,我建议普通的旧 throbber 显示“请稍候..”并阻止(设置属性 readonly =“readonly”)您的输入控件,直到 ajax 请求为止完全的。
上面的 UI 似乎是自相矛盾的!
using a modal block (block UI) means blocking any inputs from user, I'd suggest plain old throbber to show 'Please wait..' and to block ( set attributes readonly="readonly" ) ur input controls till the ajax request is complete.
The above UI seems to be self conflicting!