Обновить HTML после отправки запроса - PullRequest
0 голосов
/ 19 декабря 2018

Я пытался перезагрузить часть страницы после того, как пользователь создал сообщение.

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

Я не знаю, почему страница не перезагружает этот элемент или что я делаю неправильно.Заранее благодарим за помощь.

Кроме того, как я могу изменить кнопку после того, как пользователь отправит форму или щелкнет по ней?

1 Ответ

0 голосов
/ 19 декабря 2018

Добавьте foreach цикл в теге div и присвойте этому тегу уникальный идентификатор и используйте этот тег в файле JavaScript.

Код:

BladeФайл

<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);
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...