0
我想要做一個帳單結構,我可以選擇一個客戶端,下一個選擇窗體將向我顯示客戶端的所有項目,但出於某種原因,我正在麻煩與此。在刀片視圖中檢索JSON響應 - Laravel 5.3
這是我route.php
Route::resource('bills', 'BillsController');
Route::get('bills/items','[email protected]');
這是我BillsController
private function items($request) {
try {
if ($request) {
$id = $request->client_id;
$items = Item::where('client_id', $id)->get()->pluck('code', 'id');
return redirect()->json($items);
} else {
\Session::flash('error_message', 'Ups! Hemos tenido un error.');
return redirect()->back();
}
} catch (Exception $e) {
\Session::flash('error_message', 'Ups! Hemos tenido un error.');
return redirect()->back();
}
}
這是我的刀片視圖中查看腳本:
<script>
$(document).ready(function() {
$('#clients').change(function() {
var $client_id = $('#clients').val();
console.log($client_id);
var $url = '{{ url('MyAdmin/bills/items') }}';
console.log($url);
$.getJSON($url, {'client_id': $client_id}, function(resp) {
console.log(resp); //For some reason here the "resp" is not working
$.each(resp, function(key, answer) {
$('#items').append('<option value="'+answer.id+'">'+answer.code+'</option>');
});
});
});
});
任何想法?非常感謝!
我剛試過,不工作:( –
@CarlosOrtega直接在瀏覽器中訪問鏈接後會發生什麼 – Ohgodwhy
'ReflectionException在Route.php行333:?方法應用\ HTTP \控制器\後端\ BillsController: :show()does not exist'我得到這個 –