拉拉维尔按月列表选择选项



我对此有问题。IT 说"参数太少,无法运行 App\Http\Controllers\ViewsController::OBviews((,0 已通过,正好 1 个预期">

我的控制器:

public function OBviews($date)
{
$masterIds = DB::select('SELECT * FROM o_b_masters OBM INNER JOIN users u on OBM.emp_id = u.id INNER JOIN o_b_requests OBR 
on OBR.details_id = OBM.obmaster_id WHERE u.id =? AND MONTH(OBM.date_filed) = ?', [Auth::id(), $date]);
return response()->json($masterIds); 
}

我的路线:

Route::GET('/obView/{date}', 'ViewsController@OBviews')->name('OBRequest');

我的JS:

$('select').on('change', function (e) {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
alert(valueSelected);
$.ajax({
url: 'obView',
type: 'GET',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
data: 'date='+valueSelected,
success: function (data) {
if (data['success']) {
alert(data['success']);
} else if (data['error']) {
alert(data['error']);
} else {
alert('Whoops Something went wrong!!');
}
},
error: function (data) {
alert(data.responseText);
}
});
});

我的详细信息.刀片.php:

<select name="month" class="form-control">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
<option value="04">April</option>
<option value="05">May</option>
<option value="06">June</option>
<option value="07">July</option>
<option value="08">August</option>
<option value="09">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>

似乎当有变化时,没有任何内容传递给控制器。

您的网址需要日期细分,但在 ajax 调用中,您未指定日期细分。

将代码调整为此

$('select').on('change', function (e) {
var optionSelected = $("option:selected", this);
var valueSelected = this.value;
alert(valueSelected);
$.ajax({
url: 'obView/' + valueSelected,
type: 'GET',
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')},
success: function (data) {
if (data['success']) {
alert(data['success']);
} else if (data['error']) {
alert(data['error']);
} else {
alert('Whoops Something went wrong!!');
}
},
error: function (data) {
alert(data.responseText);
}
});
});

相关内容

  • 没有找到相关文章

最新更新