Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to redirect Laravel route from Javascript file in blade template

I have a prescription form and submitted the form using AJAX.

Now I want to automatically redirect to another route from AJAX after the form successfully submitted.

I have tried with several options like

window.location.href = "{ url('/show-all-prescription') }"

and

{{ route('/show-all-prescription')}}

AJAX CODE

jQuery.ajax({
url:"{{ url('/submit_prescription') }}",
type: 'GET',
data: {name: name, age: age, mobile_no: mobile_no},
success:function(msg){

    if(msg>0)
    {

        // window.location.href = "{ url('/show-all-prescription') }";

        {{ route('/show-all-prescription')}}

    }
}
});

And got the error

Route [/show-all-prescription] not defined

route.php

Route::get('/show-all-prescription', 'prescriptionController@show_all_prescription');

But not getting the result. Someone Help Please?

like image 642
Arafat Rahman Avatar asked Apr 06 '19 09:04

Arafat Rahman


1 Answers

In route file

Route::get('/show-all-prescription', 'prescriptionController@show_all_prescription')->name('show-all-prescription');

Then in blade file ajax request,

window.location.href = "{{ route('show-all-prescription')}}";
like image 113
iamawesome Avatar answered Sep 22 '22 13:09

iamawesome