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
ajaxrequests as the spinner provides a visual feedback that an action is ongoing. The action being arequesthas been sent to the server by the browser and the browser is now waiting on aresponse. Theresponseis required in order to remove the spinner (responsecould also be a failure or timeout etc.) and the spinner is removed without a page refresh.In your use case, the
responsefrom 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
loadingindicator (spinner, words, etc.) which is initiallyhiddenand 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
jQueryor whatever you want but you get the idea. Example jsFiddle here.