3

When i remove the parameter 'ajax' from from the .queue() function, my ajax calls do get queued. The only problem is, the jQuery 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();     

    }
  });

}

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

10 Comments

@SLaks: adding .dequeue() does not seem to fix this. I am updating my code above to reflect my addition of .dequeue
@bmarti: However, it doesn't do anything useful. It simply calls each function immediately. You should figure out when to dequeue.
@SLaks: i put the $(self).dequeue('customfunctions'); inside the success callback for my ajax call. I changed my code above to reflect these changes. It still does not seem to be working though.
@bmarti: You never kicked off the initial item.
@SLaks: What do you mean by "never kicked off the intial item"? I added a console.log() to the code above, this shows in my js console. Thanks for your help on this by the way.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.