I am submitting a form directly without using Ajax request, I want to show loader when getting a response from the backend. How is it possible?
{!! Form::open(['route' => ['patient_signup'], 'method' => 'post', 'name' => 'sign_up_form']) !!}
and in controller
public function patient_signup()
{
if ($result) {
return redirect(route('home'))->with('success', $message);
} else {
return Redirect::back()->withInput()->with('error', $message);
}
}
Everything working fine but I want to show loader when getting a response from the backend. Please provide me a better solution.
It feels like you're fudging this a little. Spinners typically work with
ajax
requests as the spinner provides a visual feedback that an action is ongoing. The action being arequest
has been sent to the server by the browser and the browser is now waiting on aresponse
. Theresponse
is required in order to remove the spinner (response
could also be a failure or timeout etc.) and the spinner is removed without a page refresh.In your use case, the
response
from the server is in fact redirecting the user to another page, or back to the form page with errors.So basically what you want to do is have a
loading
indicator (spinner, words, etc.) which is initiallyhidden
and you display when the form is submitted and it will automatically disappear if the user is redirected back to your form page.As an example:
Then your javascript:
You could use
jQuery
or whatever you want but you get the idea. Example jsFiddle here.