Skip to content Skip to sidebar Skip to footer

.ajaxcomplete Is Not Triggered After Deleting Item With Ajax?

I'm using Rails 4, Bootstrap and Masonry. I have the following code working for jQuery Masonry to arrange my divs, in application.js: $(function(){ $('#pins').masonry({ itemS

Solution 1:

From the jQuery Documentation on ajaxComplete it seems as though it doesn't perform a function call on a given argument but instead calls a handler function when the Ajax requests complete.

handler Type: Function( Event event, jqXHR jqXHR, PlainObject ajaxOptions ) The function to be invoked.

Your best bet would be to use an anonymous function to call masonryUpdate.

$(document).ajaxComplete(function(event, xhr, settings) {
  masonryUpdate();
};

Edit

It might be better to cache your masonry spec in a variable.

var mas = $('#pins').masonry({
    itemSelector: '.box',
    isFitWidth: true
});

Then you can call masonry on that variable

var masonryUpdate = function() {
  setTimeout(function() {
    mas.masonry('reload');
  }, 200);
}

Post a Comment for ".ajaxcomplete Is Not Triggered After Deleting Item With Ajax?"