Как обновить sh таблицу после ajax запроса в laravel - PullRequest
0 голосов
/ 09 февраля 2020

Я работаю над проектом обмена с использованием laravel и хочу обновить sh мою таблицу после

<tbody class="fixed-header">
                                                             @foreach($transactionsCustomer as $transaction)
                                                             <tr>
                                                                 <td>{{ $transaction->description }}</td>
                                                                 @foreach($accounts  as $account)
                                                                    @if($transaction->code == 0)
                                                                       @if($account->currency->id==$transaction->currency_id)
                                                                        <td>{{ $transaction->amount }}</td>
                                                                        <td></td>
                                                                        @else
                                                                            <td></td>
                                                                            <td></td>
                                                                        @endif
                                                                        @else
                                                                        @if($account->currency->id==$transaction->currency_id)
                                                                        <td></td>
                                                                        <td>{{ $transaction->amount }}</td>
                                                                        @else
                                                                            <td></td>
                                                                            <td></td>
                                                                        @endif

                                                                    @endif

                                                                 @endforeach
                                                                 <td><a href="{{ route('transaction.edit',$transaction->id)}}" class="btn btn-primary" >سمون</a></td>  
                                                             </tr>
                                                             @endforeach   
                                                       </tbody>

, а вот мой код ajax для хранения данных

   $("#transaction-form").submit(function(stay){
   var formdata = $(this).serialize(); // here $(this) refere to the form its submitting
    $.ajax({
        type: 'POST',
        url: "{{ route('transaction.store') }}",
        data: formdata, // here $(this) refers to the ajax object not form
        success: function (data) {
          $('input[type="text"],textarea').val('');
            updateTable();
        },
    });
    stay.preventDefault(); 
});

и вот мой метод контроллера для представления данных

public function singleCustomer(Request $request)
    {
        $customer = Customer::find($request->id);
        $accounts = Account::where('customer_id', $request->id)->get();
        $currencies = Currency::all();
       $transactionsCustomer = DB::table('transactions')->
        join('accounts','transactions.account_id' ,'=','accounts.id')->join('customers','accounts.customer_id','=','customers.id')->join('currencies','accounts.currency_id','=','currencies.id')->select('transactions.*','currencies.id as currency_id')->where('customers.id',$request->id)->get();
        return view('transaction.index',compact('currencies','customer','accounts','transactionsCustomer'));
    }

Теперь я хочу обновить sh мою таблицу после этого ajax запроса

1 Ответ

0 голосов
/ 10 февраля 2020

Вам нужно разделить таблицу в другом представлении.

Вот последовательность операций, вы получаете все данные из вашего контроллера , передаете их в представление таблицы, в основном представлении, которое вы включаете представление таблицы с использованием @ include ('table-view-route') .

И не забудьте о своем успехе ajax, вызовите updateTable () который имеет функциональность для загрузки табличного представления, используя jquery

$("#tableContainerId").load("{{url('table-view-route')}}");
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...