javascript - 将我的选择 ID 传递给路由控制器并显示到另一个刀片文件
问题描述
我正在尝试将所选内容传递id
给controller
使用route
. 但是在另一个刀片文件中没有显示任何内容。这是我的代码
我的刀片包含那个脚本
$("#state").on("change", function() {
var id = $(this).val();
console.log(id)
var cuid = document.getElementById("cu").value;
console.log(cuid)
});
状态选择
<div class="col-md-12 form-group" id="stateBranch">
<label for="sm" class="control-label">{{ __('messages.state') }}</label>
<select name="state" id="state" class="input-sm form-control">
<option value="">{{ __('messages.select') }}</option>
@if(!empty(request()->session()->get('stateList')))
@foreach(request()->session()->get('stateList') as $state)
<option value="{{ $state->st_state_code }}">{{ $state->st_state_desc }}</option>
@endforeach
@endif
</select>
</div>
选择
<div class="col-md-12 form-group" id="custbranchreport">
<label for="sm" class="control-label">{{ __('messages.module.customer') }}<span class="compulsory"> * </span></label>
<select name="cu" id="cu" class="input-sm form-control" onchange="">
<option value="">{{ __('messages.select') }}</option>
@if(!empty($custList))
@foreach($custList as $cu)
<option value="{{ $cu->cu_customer_ID }}">{{ $cu->cu_customer_Shortname }}-{{ $cu->cu_customer_Name }}</option>
@endforeach
@endif
</select>
<input id="hid" type="hidden" name="hid" value=""/>
</div>
通过 onclick 打开新窗口路由
<a class="btn btn-sm btn-default pull-right" type="button" title="Search Branch" onclick="openNewWindow('{{ route('reporting.branchCheckBoxList', ['cu' ,'state']) }}')" ><i class="fa fa-hand-o-up"></i> Choose Branch</a>
路线/web.php
Route::get('reporting/branchCheckBoxList/{cuid}/{stid?}','GenReportController@branchCheckBoxList')->name('reporting.branchCheckBoxList');
控制器
public function branchCheckBoxList(Request $request) {
$cuid = $request->get('cuid');
$stid = $request->get('stid');
return view('report.BranchCheckBoxList', compact('cuid','stid'));
}
解决方案
考虑到您在路由中使用 get 请求,您不能在方法参数中使用请求,以访问这些参数将您的控制器更改为此。
public function branchCheckBoxList($cuid, $stid = '') {
$cuid = $cuid;
$stid = $stid;
return view('report.BranchCheckBoxList', compact('cuid','stid'));
}
推荐阅读
- android - 将应用的目标 API 级别更改为至少 26
- amazon-web-services - 如何更改 AWS Cloud9 的自动休眠时间或手动将其关闭?
- python - 将 Watson Assistant 的答案传递给变量 Python
- python - 在多个日期窗口上应用熊猫滚动的更快方法
- r - 根据列的值查找重复的 ID
- html - Angular中Primeng文件上传错误消息的翻译不刷新
- pyspark - 在pySpark中连接换行符char(13)
- c - 如何在不知道其大小且不多次读取的情况下从文件加载矩阵?
- python - IPython 的高性能替代品!shell-command 魔法
- video-streaming - 通过 RTP/RTSP 流式传输 MKV(带有特技播放)