我的路线:
Route::get('deleterequest/{request_id}', 'RequestController@getDeleteRequest')->name('getDeleteRequest');
在视图中,我想点击一个标签来调用此路线 视图:
<a onclick=" confirmDelete({{ $request->task_id }})" href="#" ><span class="fa fa-trash-o"></span></a>
<script type="text/javascript">
function confirmDelete(id){
document.location.href="{!! route('getDeleteRequest', $id); !!}";
}
当我运行代码时,它显示错误消息:
未定义的变量:id
答案 0 :(得分:0)
转到your_project_folder \ config并创建文件constants.php(如果它不存在)然后在其中定义site_path常量
define('SITE_PATH', 'http://www.yoursite.org/');
window.location = SITE_PATH +'deleterequest /'+ id;
答案 1 :(得分:0)
我只需要解析它并替换..
function confirmDelete(id){
let url = "{{ route('getDeleteRequest', ':id') }}";
url = url.replace(':id', id);
document.location.href=url;
}
或只是
<a onclick="confirmDelete({{route('getDeleteRequest', $request->task_id) }})" href="#" ><span class="fa fa-trash-o"></span></a>
function confirmDelete(url){
document.location.href=url;
}