できる限り説明しようと思います。基本的に、アイテムのグリッド (石積み) があり、各グリッド div (赤) 内に ajax で読み込まれたコンテンツ (wordpress single.php 投稿) を追加したいと考えています。
コンテンツを入力する各赤い div 内にajaxcontainerという div クラスがあります。a href トリガー コンテンツをクリックすると必要に応じて追加されますが、これは 1 回機能しますが、グリッド内の別の項目をクリックすると、古い ajaxcontainer にその href からの新しいコンテンツが読み込まれます。基本的に複製。
別のアイテムをクリックしても、古い ajaxcontainer に古いコンテンツを保持させたい。
HTML
<article style="background:<?php echo $color ?>;" id="post-<?php the_ID(); ?>"
<?php post_class($classes); ?>>
<div class="hover">
<h2><?php echo $head ?></h2>
<p class="tags"><?php echo $tagsstring; ?></p>
<a href="//<?php echo $url ?>"><?php echo $url ?></a>
<a class="trick" rel="<?php the_permalink(); ?>" href="<?php the_permalink();?>">goto</a>
</div>
<div class="thumbnail <?php echo $paddingstring?>" style="background-image:url(<?php echo $thumbnail[0] ?>);">
</div>
</article><!-- #post-## -->
私が今持っているもの:
$.ajaxSetup({
cache: false,
success: function (result, status, xhr) {
// not showing the alert
console.log('success');
var $this = jQuery(this)
$('.ajaxcontainer', $this).hide().fadeIn();
},
beforeSend: function () {
console.log('beforesend');
$(".ajaxcontainer").html("loading...");
},
complete: function (xhr, stat) {
// hide dialog // works
}
});
$(".trick").each(function () {
$(this).on("click", function (e) {
$(this).parents('.item').append("<div class='ajaxcontainer'>hello world</div>")
var post_link = $(this).attr("href");
$(".ajaxcontainer").load(post_link + ' #content');
return false;
});
});
どんな助けでも大歓迎です:)