用户创建帖子后,我一直在尝试重新加载页面的一部分。
JavaScript
success: function(result)
{
$("#postsxd").load(" #postsxd");
console.log(result);
}
刀片
@foreach(Auth::user()->posts()->latest()->paginate(1) as $userpost)
<div class="ui-block" id="postsxd">
<article class="hentry post">
<div class="post__author author vcard inline-items">
<img src="{{ $userpost->user->getFirstMediaUrl('pps') ? $userpost->user->getFirstMediaUrl('pps') : '/img/ava_10.jpg' }}"
width="36" height="36" alt="author">
<div class="author-date">
<a class="h6 post__author-name fn" href="#">{{ $userpost->author }}</a>
<label style="font-size: 12px;">(Your latest post)</label>
<div class="post__date">
<time class="published" datetime="2004-07-24T18:18">9 hours ago</time>
</div>
</div>
</div>
<p>{!! $userpost->content !!}</p>
</article>
</div>
@endforeach
我不知道为什么页面不重新加载该元素或我做错了什么。预先感谢您的帮助。
此外,在用户提交或单击表单后如何更改按钮?
答案 0 :(得分:1)
在foreach
标记中添加div
循环,并为该div标记赋予唯一的ID,并在javascript文件中使用该标记。
代码:
刀片文件
<div id="#uniqueId">
@foreach(Auth::user()->posts()->latest()->paginate(1) as $userpost)
<div class="ui-block" id="postsxd">
<article class="hentry post">
<div class="post__author author vcard inline-items">
<img src="{{ $userpost->user->getFirstMediaUrl('pps') ? $userpost->user->getFirstMediaUrl('pps') : '/img/ava_10.jpg' }}"
width="36" height="36" alt="author">
<div class="author-date">
<a class="h6 post__author-name fn" href="#">{{ $userpost->author }}</a>
<label style="font-size: 12px;">(Your latest post)</label>
<div class="post__date">
<time class="published" datetime="2004-07-24T18:18">9 hours ago</time>
</div>
</div>
</div>
<p>{!! $userpost->content !!}</p>
</article>
</div>
@endforeach
</div>
JavaScript | Ajax响应
success: function(result)
{
$("#uniqueId").load(" #uniqueId > *");
console.log(result);
}