How do I know if jQuery has an Ajax request pending?(我如何知道 jQuery 是否有待处理的 Ajax 请求?)
问题描述
我在使用我们制作的 jQuery 控件时遇到了一些问题.假设您有一个下拉列表,允许您输入要查找的项目的 ID,当您按 ENTER 或在文本框中失去焦点时,它会通过 jQuery 验证您输入的 ID 是否正确,如果没有则显示警报不.
I'm having some problems with a jQuery control we made. Suppose you have a dropdownlist that allows you to enter the ID of the item you're looking for, and when you press ENTER or lose focus in a textbox it validates via jQuery that the ID you entered is correct, showing an alert if it doesn't.
问题是当普通用户在其中输入了一个无效的值并通过按下提交按钮失去焦点时,jQuery post在表单的提交发送后返回.
The thing is that when an ordinary user enters an invalid value in it and loses focus by pressing the submit button, the jQuery post returns after the submit of the form has been sent.
有什么方法可以检查 jQuery 是否有任何异步请求处理,以便我不允许表单提交?
Is there any way that I can check if there's any Async request processing by jQuery so that I do not allow the form submit?
推荐答案
你可以使用 ajaxStart和 ajaxStop 来跟踪请求何时处于活动状态.
You could use ajaxStart and ajaxStop to keep track of when requests are active.
这篇关于我如何知道 jQuery 是否有待处理的 Ajax 请求?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:我如何知道 jQuery 是否有待处理的 Ajax 请求?


基础教程推荐
- Chart.js 在线性图表上拖动点 2022-01-01
- 如何使用JIT在顺风css中使用布局变体? 2022-01-01
- 我可以在浏览器中与Babel一起使用ES模块,而不捆绑我的代码吗? 2022-01-01
- Electron 将 Node.js 和 Chromium 上下文结合起来意味着 2022-01-01
- 如何使用TypeScrip将固定承诺数组中的项设置为可选 2022-01-01
- html表格如何通过更改悬停边框来突出显示列? 2022-01-01
- 自定义 XMLHttpRequest.prototype.open 2022-01-01
- 直接将值设置为滑块 2022-01-01
- Vue 3 – <过渡>渲染不能动画的非元素根节点 2022-01-01
- 用于 Twitter 小部件宽度的 HTML/CSS 2022-01-01