[英]How to fix error GET http:… 404(not found)
我想獲取下拉列表的值並顯示文本框,但我的代碼不起作用
這是我的代碼:Controller:
public function socaucuachuong($id)
{
$units = CauHoi::groupBy('chuong')->select('chuong', CauHoi::raw('count(id) as Total'))->where('idmonthi','=', $id)->get()->toArray();
return view('DeThi::dethi',compact('units'));
}
查看: dethi.blade.php
$('select').select();
function get_units() {
var id = $('#id_select').val();
var list = $('#dschuong');
list.empty();
var url = "{{ route('dthi.socaucuachuong') }}"+'/'+id;
var success = function (result) {
if (result.length <= 0) {
var item = '<div class="input-field"><input type="text" disabled value="Môn này hiện chưa có câu hỏi nào"></div>';
list.append(item);
} else {
for (i = 0; i < result.length; i++) {
var item = '<div class="input-field"><label for="unit-' + result[i].chuong+ '">Nhập số câu hỏi chương ' + result[i].chuong+ ' (có ' + result[i].Total + ' câu) <span class="failed">(*)</span></label><input type="number" max="' + result[i].Total + '" class="unit_input" onchange="set_sum(' + result[i].Total + ')" name="unit-' + result[i].chuong+ '" id="unit-' + result[i].chuong+ '" required></div>';
list.append(item);
}
}
};
$.get(url, success);
}
路線:
Route::get('dethi/socau', 'App\Modules\DeThi\Controllers\DeThiController@socaucuachuong')->name('dethi.socaucuachuong');
Route::resource('dethi', DeThiController::class);
當我 select 下拉列表時我的錯誤:
我怎樣才能解決這個問題?
路線
Route::get('dethi/socau/{id}', 'App\Modules\DeThi\Controllers\DeThiController@socaucuachuong')->name('dethi.socaucuachuong');
Javascript(刀片)
var url = '{{ "dthi.socaucuachuong", ":id") }}';
url = url.replace(':id', id);
您缺少傳遞的 ID 的路由參數。
https://laravel.com/docs/8.x/routing#required-parameters
基本上,您的路線需要更新為
Route::get('dethi/socau/{id}', 'App\Modules\DeThi\Controllers\DeThiController@socaucuachuong')->name('dethi.socaucuachuong');
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.