php - Laravel call a function after view is rendered -


i working on laravel website has basic functionality of searching flights/hotels etc.. 1 thing want show loading page after user submits search information animation happening while api runs.

problem can't figure out way show page , run controller code @ same time. i've been trying pagescontroller pass flightscontroller view

pagescontroller.php

public function flight_search( request $request ) {      $flightscontroller = new flightscontroller();      return view('flights.flight-search', [         'flightscontroller' => $flightscontroller,         'user_input' => $request         ]); } 

and calling function in flight-search view

flight-search.blade.php

@extends('app')  @section('content') <div class="container-fluid">     <div class="row">         <div class="col-md-8 col-md-offset-2">             <div class="page-heading">searching available tickets...</div>         </div>     </div>     <div class="row">         <div class="col-md-8 col-md-offset-2">             <div class="progress">                 <div class="progress-bar progress-bar-striped progress-bar-warning active" role="progressbar" aria-valuemin="0" aria-valuemax="100" style="width:100%">                 </div>             </div>         </div>     </div> </div>  {{ $flightscontroller->search( $user_input ) }}  @endsection 

but page load waits function call finish complete, , search() method returns next view search result.

any suggestions on how should proceed this?

the server send response after whole request processed you're trying won't work. common solution show loading screen, send ajax request server fetch result and, once results loaded, hide loading screen , show result. of course has done javascript, not php.

so scenario be:

  • user fills form
  • user clicks "search"
  • show loading screen javascript
  • send ajax request backend result javascript
  • when results fetched, hide loading screen , show results javascript

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -