开发者

Using jquery's .queue to queue functions

When i remove the parameter 'ajax' from from the .queue() function, my ajax calls do get queued. The only problem is, the jQ开发者_JS百科uery docs say that the .queue() function will then default to the 'fx' queue. Unfortunately, I am already using this queue (for effects) and I want to use another queue specifically for custom functions. Unfortunately, the code inside the .queue() function never gets called. I have an example of my code below (just a small snippet). It is getting a little complicated if you have further questions feel free to comment.

$(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();     

    }
  });

}


You need to call dequeue() to run the next function in the queue.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜