Ara*_*man 5 javascript php jquery laravel laravel-blade
我有一个处方表格并使用 AJAX 提交了表格。
现在我想在表单成功提交后自动从 AJAX 重定向到另一个路由。
我试过几个选项,比如
window.location.href = "{ url('/show-all-prescription') }"
Run Code Online (Sandbox Code Playgroud)
和
{{ route('/show-all-prescription')}}
Run Code Online (Sandbox Code Playgroud)
阿贾克斯代码
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')}}
}
}
});
Run Code Online (Sandbox Code Playgroud)
并得到了错误
路线 [/show-all-prescription] 未定义
路由文件
Route::get('/show-all-prescription', 'prescriptionController@show_all_prescription');
Run Code Online (Sandbox Code Playgroud)
但没有得到结果。有人帮忙吗?
小智 12
在路由文件中
Route::get('/show-all-prescription', 'prescriptionController@show_all_prescription')->name('show-all-prescription');
Run Code Online (Sandbox Code Playgroud)
然后在刀片文件ajax请求中,
window.location.href = "{{ route('show-all-prescription')}}";
Run Code Online (Sandbox Code Playgroud)