如何将数据传递给视图,并在laravel中返回response()以及ajax成功的数据

i have a grid in which all users are shown . the grid is created and shown by ajax , it has 3 buttons . add , edit , remove . i can add and delete , but since in the update.blade.php i have the user image ( which is shown by a route and controller like : <img src="{{ route('userimage',['id' => $pass_the_id ])}}"/> , the problem now is how do i pass variable like $pass_the_id that i'm about to use in the view blade ?` , this is the code that brings up the modal ( when edit button which is right in front of user name and id is clicked . i can get user name , family and so on and show it in the modal . but how do i pass the $id to the image route that i mentioned above ?

    $('body').delegate('#student-info #edit','click',function (e) {
    var id = $(this).data('id');
    $.get("{{ URL::to('student/edit') }}",{id:id},function (data) {
        $('#frm-update').find('#id').val(data.id);
        $('#frm-update').find('#name').val(data.name);
        $('#frm-update').find('#family').val(data.family);
        $('#frm-update').find('#username').val(data.username);
        $('#frm-update').find('#birth_date').val(data.birth_date);
        $('#frm-update').find('#phone').val(data.cell_phone);
        $('#frm-update').find('#email').val(data.email);
        $('#frm-update').find('#gender').val(data.gender);

        $('#student-update').modal('show');
    })
}) 

here is the laravel Controller function that is called on URL::to('student/edit') wich i have mentioned in the above $.get code :

    public function edit(Request $request) {
    if($request->ajax()) {
        $contact = User::find($request->id);
        return response($contact);
    }
}

the responsibility of above controller function which is called during $.get is to get the information based on the id that i have passed . ( my grid already shows each user id in the the grid table i've created . but i don't know how to pass it to the src="{{ route('userimage',['id' => $pass_the_id ])}}"

here is what userimage route is doing : bellow is the route :

    Route::get('userimage/{id}','ImageController@showimage')->name('userimage');

and this is its code :

    public function showimage($id) {
    if(UserImages::selectuserimage($id) !== null) {
        $imageData = UserImages::selectuserimage($id);
        $info = $info = base64_decode($imageData);
        $img = Imgs::make($info);
        $img->encode('jpg',80);
        return $img;
    }
    else return public_path('images/Atehran.jpg');
}

On Ajax Success call to pass data to view with return response() in laravel this is the simple way with an example -

js function

$(document).on('change', '[name="abc_field"]', getCitiesByState);

 function yourAjaxCall() {
    var data_to_pass = $(`[name='get_data_selector']`).val();
    var $selector    = $(`[name='selector']`);
    $.ajax({
        url: route('your_route'),
        type: 'GET',
        data: {
            data: data_to_pass
        },
        dataType: "json",
        success: function success(data) {
            $selector.empty().append(data);
        },
    });
}

call to controller from ajax call

public function your_route_function()
{
    $result = Abc::where('column',request('data'))->get();

    return response()->json([
        'result' => view('viewfilename.fields._option', ['options' => $result])->render(),
    ]);
}

view path "resources\viwes\viewfilename\fields_option.blade" to render

<option value="">{{ $defaultText or 'Select' }}</option>
@foreach($options as $value => $name)
    <option value="{{ $value }}">{{ $name }}</option>
@endforeach

Hope this will help you to render view through ajax call.