簡體   English   中英

如何在JQuery中做到這一點? (獲取從AJAX-GET返回的HTML,並將其變成一個對象)

[英]How do I do this in JQuery? (get the HTML returned from AJAX-GET and turn it into an object)

$.ajax({
                method:"get",
                url:"/wall",
                data:"ajax=1",
                beforeSend:function(){},
                success:function(html){
                   $("#grid_mason").append(html);  //Add the next boxes to the Grid.
                   $(this).masonry({ appendedContent: $( html ), animate:false, resizeable:false });

                    });

                }
            });

http://desandro.com/demo/masonry/docs/appending.html

我正在使用該Masonry插件,並且有關附加的討論。

我認為您需要將代碼重構為:

var thiz = this;
$.ajax({
    method:"get",
    url:"/wall",
    data:"ajax=1",
    beforeSend:function(){},
    success:function(html){
       $("#grid_mason").append(html);  //Add the next boxes to the Grid.
       $(thiz).masonry({ 
            appendedContent: $( html ),
            animate:false, 
            resizeable:false});
    });
   }
});

如果您將砌體應用於#grid_mason嘗試從以下位置更改代碼

$("#grid_mason").append(html);
$(thiz).masonry({ appendedContent: $( html ), animate:false, resizeable:false });

對此

$("#grid_mason").append(html)
    .masonry({ appendedContent: $( html ), animate:false, resizeable:false });

不知道我是否可以建議其他任何內容而無需查看更多代碼。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM