簡體   English   中英

發布請求后重新加載HTML

[英]Reload HTML After Post Request

用戶創建帖子后,我一直在嘗試重新加載頁面的一部分。

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

我不知道為什么頁面不重新加載該元素或我做錯了什么。 先謝謝您的幫助。

另外,在用戶提交或單擊表單后如何更改按鈕?

div標簽中添加foreach循環,並為該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);
}

暫無
暫無

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

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