- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 jQuery 1.4.4,想知道是否可以将 .live() 用于 Ajax 事件,例如 ajaxStart/ajaxComplete。我已经用 .bind() 绑定(bind)了这些事件,并且它一直有效
jQuery(sourceId).bind("ajaxSend", function(event, xhr, ajaxOptions) {
// do something
});
equivalent
jQuery(sourceId).ajaxSend(function(event, xhr, ajaxOptions) {
// do something
});
与 .live() 的绑定(bind)更适合我的用例。有可能吗?我在某处读到以下代码片段不起作用
jQuery(sourceId).live("ajaxSend", function(event, xhr, ajaxOptions) {
// do something
});
预先感谢您的回复。
最佳答案
您不能使用 live() 来执行此操作,尽管您可以使用自定义事件来执行此操作。
live() 的含义是动态添加元素。动态加载的元素必须作为某些事件或 AJAX 回调的结果来完成,以便在回调事件上设置新的事件绑定(bind)。
callback event...
//code thatadds the new elements...
jQuery('selector that identifies the new elements').bind("ajaxSend", function(event, xhr, ajaxOptions) {
// do something
});
您可能希望将代码包装在函数中。
看看这里的评论,复制自http://api.jquery.com/live/
The .live() technique is useful, but due to its special approach cannot be simply substituted for .bind() in all cases. Specific differences include:
DOM traversal methods are not supported for finding elements to send to .live(). Rather, the .live() method should always be called directly after a selector, as in the example above.
To stop further handlers from executing after one bound using .live(), the handler must return false. Calling .stopPropagation() will not accomplish this.
In jQuery 1.3.x only the following JavaScript events (in addition to custom events) could be bound with .live(): click, dblclick, keydown, keypress, keyup, mousedown, mousemove, mouseout, mouseover, and mouseup.
As of jQuery 1.4 the .live() method supports custom events as well as all JavaScript events that bubble.
As of jQuery 1.4.1 even focus and blur work with live (mapping to the more appropriate, bubbling, events focusin and focusout).
As of jQuery 1.4.1 the hover event can be specified (mapping to mouseenter and mouseleave, which, in turn, are mapped to mouseover and mouseout).
关于jquery - .live() 可以用于 ajaxStart 和 ajaxComplete 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5564779/
如果之后,有没有办法判断调用是成功还是失败? 如果之前,有没有办法在成功函数运行后(每次调用时)运行函数? 最佳答案 您可以在多种情况下控制ajax请求: $.ajax({ // some o
我一直致力于为 AJAX 请求制作一个简单的加载函数。 AJAX 对我来说还很陌生,所以我确信我只是在做一些愚蠢的事情! ajaxStart 触发并开始加载 spinner.gif,但 ajaxCom
我正在研究用于打印 IFrame 的 Opera 解决方法。现在我们都知道打印iframe的唯一方法就是在新窗口中打开然后打印。我面临的问题是,当我的 IFrame 在新窗口中打开时,会触发一系列 a
我遇到了这个问题,并不是所有的 ajaxComplete 调用都被触发了。 我的代码 $(document) .ajaxStart(function () { $.blockUI(); })
我不明白为什么这不起作用,我已经在 stackoverflow 上查看了很多问题,但没有发现我的代码有任何问题。 我有一个#loading div,我想在ajax 调用完成后删除它。这是我的代码,从未
您好,我目前在触发 .ajaxComplete 函数时遇到问题,它应该可以在演示站点上运行。我从这里引用这个函数 http://www.bitrepository.com/a-simple-ajax-
在我的代码中,prices.html 文件未加载。我希望加载prices.html 文件,然后我想在最后表示感谢。但它直接显示感谢消息。 这样ajaxComplete()可以工作吗?
我有这个代码: $( document ).ajaxComplete(function( event, xhr, settings ) { console.log('test'); }); 我
我有一个全局 ajaxComplete 处理程序: $('body').ajaxComplete(function (event, request, settings) {
我有一个加载函数,希望代码在加载时将一些 html 写入 div,并在加载完成时显示页面。我看到了一些关于 ajaxStart 和 ajaxComplete 事件的小文章,但是我不确定如何实现它们。
一直在这个网站上工作... http://redrhinorestoration.com/wp/ 但是,当您单击“服务”,然后尝试单击“显示服务”以向上滑动服务时,它不起作用。我在这里发布并获得了一些
我正在开发一个 Google Chrome 扩展程序,以便为我经常访问的网站提供一些附加功能,这让我尝试在 AJAX 请求成功时再次运行脚本。由于站点的性质,这是必要的。 继续:简单地说,我想要做的是
我有一个用 php 编写的后端和一个用 jQuery 编写的前端..我想要做什么: 页面包含多个带有 AJAX 调用的链接(每个链接都有自己的成功/错误回调) php 后端可能会返回如下回复:{"mu
两个函数需要在 Javascript 中执行,其中一个函数应该在另一个函数完成时启动。 第一个使用 getJSON 填充数组,然后第二个将对其进行操作。 但是,getJSON 是异步的,它不会暂停执行
我使用的是 jQuery 版本 1.5.1,但这对我不起作用: $(window).ajaxComplete(function() { console.log('hello')
我希望我的 JS 的某些部分在文档准备好或 ajax 查询完成时初始化 像这样的事情: if ($(document).ready() or $(document).ajaxComplete()) {
我在单击单选按钮时发送 ajax post 请求。 // Get phone number if user selects phone option $('.rdoPhone').click
我感谢所有的帮助。我是一个初学者,几乎没有 jQuery/AJAX 经验,我一直在疯狂地试图弄清楚为什么我无法弄清楚这一点。 我正在编写一个 Facebook 页面应用程序,让用户授予权限并将视频上传
我有一个关于 .ajaxComplete() 的问题。 假设我这样做: // Register an ajaxComplete (pseudo code ish) $('#someId').ajaxC
看到这个“从 jQuery 1.8 开始,.ajaxComplete() 方法只能附加到文档。”在 jQuery 文档中,所以我想知道为什么它必须附加到文档中。正如我所尝试的,如果我将它附加到窗口或其
我是一名优秀的程序员,十分优秀!