【发布时间】:2010-11-15 15:44:10
【问题描述】:
当我从 .queue() 函数中删除参数“ajax”时,我的 ajax 调用确实会排队。唯一的问题是,jQuery 文档说 .queue() 函数将默认为“fx”队列。不幸的是,我已经在使用这个队列(用于效果)并且我想使用另一个专门用于自定义功能的队列。不幸的是,.queue() 函数中的代码永远不会被调用。我在下面有一个我的代码示例(只是一个小的 sn-p)。如果您还有其他问题,请随时发表评论,这会变得有点复杂。
$(document).ready(function(event) {
var target = event.target;
var ajaxify = new Ajaxify();
$.each(ajaxify.functions, function(index, value){
if ($(target).hasClass(value)) {
console.log('this is in my console, and nowhere else in my code');
$('#main').queue('customfunctions', function (next) {
var self = this;
ajaxify[value](target, event, next, self);
});
}
});
$('#main').dequeue('customfunctions');
});
function Ajaxify() {
this.functions = [
'ajaxify_overlay',
'ajaxify_overlayCancel',
'ajaxify_overlaySubmit',
'ajaxify_rollout',
'ajaxify_rolloutCancel',
'ajaxify_rolloutSubmit',
'ajaxify_upload',
'ajaxify_contentArea',
'ajaxify_itemToggler',
'ajaxify_closer',
'ajaxify_submit',
'ajaxify_inputActivate',
'ajaxify_executeAndRefresh',
'ajaxify_empty' //no comma on the last entry!!!!
];
}
Ajaxify.prototype.ajaxify_executeAndRefresh = function (target, event, next, self) {
event.preventDefault();
var newPath = getVar($(target).attr('class'), 'url'); //getVar function not included, it will get the new path for the ajax call below
var url = $(target).attr('href');
$.ajax({
type: "POST",
url: url,
success: function(transport) {
refreshPage(newPath); //refreshPage function not included, it will do a page refresh with the new path
next();
}
});
}
【问题讨论】:
标签: javascript jquery queue