Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将jQuery与AJAX结合使用_Jquery_Ajax_Plugins - Fatal编程技术网

将jQuery与AJAX结合使用

将jQuery与AJAX结合使用,jquery,ajax,plugins,Jquery,Ajax,Plugins,我正在使用jQuery插件“砌体”(http://masonry.desandro.com/)整理一些div。这些div都加载了AJAX,不知怎的,插件启动得太早,位置也错了。 如何在这些函数中设置适当的延迟 function loadALLtheposts(id) { $.ajax({ url: "******.php", data: {userID: id}, type: "POST", dataType: "text", contentType: "

我正在使用jQuery插件“砌体”(http://masonry.desandro.com/)整理一些div。这些div都加载了AJAX,不知怎的,插件启动得太早,位置也错了。 如何在这些函数中设置适当的延迟

function loadALLtheposts(id) {
$.ajax({
    url: "******.php",
    data: {userID: id},
    type: "POST",
    dataType: "text",
    contentType: "application/x-www-form-urlencoded; charset=utf-8",
    success: function (data) {
        $('#timeline-posts').html(data);
        masonry_index();
    }
});
}

function masonry_index() {
$('#timeline-posts').masonry({
    itemSelector : '.post-wrapper',
    columnWidth : 266
});
}

提前感谢。

您应该使用标准的DOM事件-domsubtreemedited(已弃用)

改用

请注意,以上代码中的任何部分都经过测试。:)。其他可能有用的SO链接-

$("#timeline-posts").bind("DOMSubtreeModified", function() {
    masonry_index(); //this is called only after the #timeline-posts changes.
    $(this).unbind('DOMSubtreeModified'); //if required do this
});
var target = $('#some-id');
var observer = new MutationObserver(function(mutations, observer) {
    //mutation occured
    masonry_index();
});
var config = { attributes: true, childList: true, characterData: true }; //there are others that you can choose. Follow the link above.
observer.observe(target, config);
//if you want to stop observing
observer.disconnect();