laravel视图未获取所需数据

时间:2019-03-26 21:18:57

标签: laravel view

我是laravel世界的新手。我正在控制台中获取所需的数据,但未在表中获取该数据。并在我的表[object Object]中获得这样的文本。我为此编写了一些ajax,它在控制台中运行良好,但视图未获取该数据。这是我的视图和ajax代码。请进行评论

//我的视图和Ajax     

        <option value="">--- Select State ---</option>

        @foreach ($classes as $key => $value)

            <option value="{{ $key }}">{{ $value }}</option>

        @endforeach

    </select>

    <table id="studentsData" class="table table-striped table-bordered table-list-search">
        <thead>
            <tr>
                <th>#</th>
                <th>Student ID</th>
                <th>Student Name</th>
                <th>Attendance</th>
            </tr>
        </thead>
            @foreach($students as $student)
        <tbody>
            <tr>
                <th>{{$student->id}}</th>
                <td>{{$student->student_id}}</td>
                <td>{{$student->first_name}} {{$student->last_name}}</td>
                <td>
                    <div class="form-group">
                        <select class="form-control" id="gender">
                            <option>Present</option>
                            <option>Absent</option>
                            <option>Leave</option>
                        </select>
                    </div>
                </td>
            </tr>
        </tbody>
            @endforeach
    </table>
    <a class="fas fa-folder-open btn btn-success float-right mb-4 mr-2"> Save</a>
</div>



<script>

    $(document).ready(function() {

        $('select[name="students_class_id"]').on('change', function() {

            var classID = $(this).val();

            if(classID) {

                $.ajax({

                    url: '/myform/ajax/'+classID,

                    type: "GET",

                    dataType: "json",


                    success:function(data) {


                        // console.log(data);

                        $('table[id="studentsData"]').empty();

                        $.each(data, function(key, value) {

                            $('table[id="studentsData"]').append('<td   value="'+ key +'">'+ value +'</td  >');

                        });


                    }

                });

            }

            // else{
            //
            //     $('table[id="studentsData"]').empty();
            //
            // }

        });

    });

</script>

0 个答案:

没有答案