5 months ago

Referring the json data to html template | Laravel

Posted 5 months ago by lewanay

Hello everyone I m getting data from data base through ajax in the form of json... Now i can display it but for that i have some random html code inside my ajax code and what i want is to refer this ajax to the above my actual table and display it there ... Is it possible or any alternative way here ?? Below is my code

//My code

<select name="students_class_id" class="form-control" style="width:350px">

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

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

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



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




    $(document).ready(function() {

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

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

            if(classID) {


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

                    type: "GET",

                    dataType: "json",

                    success:function(data) {

                        // $('#studentsData').html(response);


                        $.each(data, function(key, value) {
                            var markup = '<tr> <td>' + value.id + '</td> <td>' + value.student_id + '</td> <td>' + value.first_name+ ' '  + value.last_name + '</td> <tr>';








Please sign in or create an account to participate in this conversation.