テキストボックスのドロップダウンから値を選択した後、AJAXリクエストを使ってデータをロードしたい。ただし、ドロップダウンから選択すると、500 (Internal Server Error)
が表示されます。どうすれば解決できますか?ここでLaravel ajax postは500内部サーバエラーを返す
は私のAJAXコードである:ここで
$('#teacher').on('change',function(e){
var tech_id = $('#teacher option:selected').attr('value');
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$.ajax({
type: "POST",
url: "{{url('ajaxteach')}}",
data: {
tech_id: tech_id
},
success: function(data) {
var json_obj = jQuery.parseJSON(data);
$('#credit_taken').val(json_obj.credit_taken);
$('#remaining_credit').val(json_obj.remaining_credit);
}
});
});
は私のコントローラである。ここ
public function get_teach(Request $request)
{
$tech_id = $request::input(['tech_id']);
$teachers= \App\Teacher::where('teacher_id','=',$tech_id)->get();
return Response::json($teachers);
}
がルートである:jqueryのAJAX呼び出しで
Route::post('ajaxteach', [
'uses' => '[email protected]_teach',
'as' => 'ajaxteach',
]);
ネットワークの応答を確認し、エラーの内容を確認します。 – Anderscc
コントローラファイルを投稿する方法ですか? –