在Prototype中,我可以使用以下代码显示"loading ..."图像:
var myAjax = new Ajax.Request( url, {method: 'get', parameters: pars,
onLoading: showLoad, onComplete: showResponse} );
function showLoad () {
...
}
Run Code Online (Sandbox Code Playgroud)
在jQuery中,我可以将服务器页面加载到一个元素中:
$('#message').load('index.php?pg=ajaxFlashcard');
Run Code Online (Sandbox Code Playgroud)
但是如何像在Prototype中那样将加载微调器附加到此命令?
jquery language-interoperability spinner equivalence prototypejs
我正在使用.ajaxStart()和.ajaxStop()在发出ajax请求时显示模态.(开始和停止之间)
现在我想添加一个等待通知的longpoll函数,类似于本网站左上角的那个.
我现在的问题在于仅为longpolling请求禁用此模式.
注册"加载屏幕"打开和关闭处理程序:
$(document).ajaxStart(handleAjaxStart);
$(document).ajaxStop(handleAjaxStop);
Run Code Online (Sandbox Code Playgroud)
我的longpoll功能:
$.ajax({
timeout: 35000,
url: longPollUrl,
success: function(data){
if(data.queCount) $('#numQueCount').html(data.queCount);
if(data.queAccept) $('#numQueAccept').html(data.queAccept);
},
dataType: 'json',
complete: longpoll
});
Run Code Online (Sandbox Code Playgroud)
我试过了:
$().off('ajaxStart');
$().off('ajaxStop');
Run Code Online (Sandbox Code Playgroud)
..开始投票后重新连接处理程序,但没有快乐.
我也尝试将一个全局变量引入到handleAjaxStart()该函数的第一行返回,但这似乎完全杀死了加载屏幕.
任何想法如何实现这一目标?
我对站点文档进行了一些ajax调用,根据ajax状态显示或隐藏进度条
$(document).ajaxStart(function(){
$('#ajaxProgress').show();
});
$(document).ajaxStop(function(){
$('#ajaxProgress').hide();
});
Run Code Online (Sandbox Code Playgroud)
我想基本上在网站的其他部分覆盖这些方法,在这些部分上进行了很多快速的小型ajax调用,并且不需要进出弹出的进度条.我试图将它们附加到其他$ .getJSON和$ .ajax调用中或插入它们.我试过把它们链接起来,但显然这并不好.
$.getJSON().ajaxStart(function(){ 'kill preloader'});
Run Code Online (Sandbox Code Playgroud) 我试图在我的页面上的ajax调用期间显示加载微调器.我想针对不同的ajax调用并显示不同的微调器.事实上,由于ajaxStart是一个全局事件,所有ajax调用最终会同时显示所有微调器.
这工作...它将类"加载"添加到包含微调器的隐藏div并显示它.
$(document).bind("ajaxStart", function () {
$body.addClass("loading");
});
$(document).bind("ajaxStop", function () {
$body.removeClass("loading");
});
Run Code Online (Sandbox Code Playgroud)
现在从其他堆栈的答案我已经看到你可以添加命名空间到ajaxstart/stop(jQuery我应该使用多个ajaxStart/ajaxStop处理)
......沿着这条线
$(document).bind("ajaxStart.secondCall", function () {
$body.addClass("loading2");
});
$(document).bind("ajaxStop.secondCall", function () {
$body.removeClass("loading2");
});
Run Code Online (Sandbox Code Playgroud)
但这并不适用于目前的形式.任何指导将不胜感激...
更新:
作为ILYAS解决方案的补充并基于他的指导我在AJAX CALL中实现了AJAX START功能....
function sendResponse(thread_id){
$(document).off(".reference_call");
$(document).on("ajaxStart.secondCall", function () {
$('.spinner').show();
});
$.ajax({
url: 'someURL.php',
type: 'post',
data: {
//data
},
success: function(data) {
$(document).on("ajaxStop.secondCall", function () {
$('.spinner').hide();
});
//do stuff....
} else {
//do stuff....
}
}
});
return false;
}
Run Code Online (Sandbox Code Playgroud) 以下代码警告"未定义",并且不会像我预期的那样在响应数据中附加html.有谁知道为什么?
JavaScript的:
$(function() {
$('.document').on('click', '.ajax', function(e) {
e.preventDefault();
// ajax request
$.ajax({
async: true,
cache: false,
type: 'post',
url: '/echo/html/',
data: {
html: '<p>This is echoed the response in HTML format</p>',
delay: 1
},
dataType: 'html',
beforeSend: function() {
console.log('Fired prior to the request');
},
success: function(data) {
console.log('Fired when the request is successfull');
$('.document').append(data);
},
complete: function() {
console.log('Fired when the request is complete');
}
});
});
});?
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="document">
<a class="ajax" href="#">Fire an AJAX request</a>
</div>? …Run Code Online (Sandbox Code Playgroud) jquery ×5
ajax ×4
equivalence ×1
long-polling ×1
preloader ×1
progress-bar ×1
prototypejs ×1
spinner ×1