I've been trying to reload a portion of the page after the user created a post.
JavaScript
success: function(result)
{
$("#postsxd").load(" #postsxd");
console.log(result);
}
Blade
@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
I don't know why the page does not reload that element or what I am doing wrong. Thanks in advance for the help.
Also, how can I change a button after the user submits the form or clicks it?
Add foreach
loop in a div
tag and give a unique id to that div tag and use that tag in the javascript file.
Code :
Blade File
<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 Responce
success: function(result)
{
$("#uniqueId").load(" #uniqueId > *");
console.log(result);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.