function get_data() {

    axios
        .get('http://cmm.ai:8088/api/get_class')
        .then(
            (response) => {
                courseData = response.data.classes
                console.log(courseData);
                var contentarticle = '';
                for (var i = 0; i < courseData.length; i++) {
                    console.log(i + 1);
                    var itemnum = i + 1
                    contentarticle += '\
            <tr> \
            <td>'+ itemnum + '</td>\
            <td >'+ courseData[i].name + ' </td>\
            <td>'+ courseData[i].start_time + '</td>\
            <td>'+ courseData[i].end_time + '</td>\
            <td>'+ courseData[i].location + '</td>\
            <td>'+ courseData[i].lecturer + '</td>\
            <td>'+ courseData[i].organizer + '</td>\
            <td>'+ courseData[i].contact + '</td>\
            <td>\
                <div>\
                    <button id="'+ courseData[i].class_id + '" class="btn__delete" type="submit" value="' + courseData[i].class_id + '");"><i class="fas fa-trash-alt"></i></button>\
                </div>\
            </td>\
            </tr>\
            '
                }

                $('.class_list_table').html(contentarticle);

            })
        .catch((error) => console.log(error))


}

get_data();



$(".btn__delete").on("click", function () {
    var delete_id = $(this).val();
    console.log(delete_id)
});



$(document).on("click", ".btn__delete", function (event) {
    console.log(1);
    var delete_id = $(this).val();
    console.log(delete_id);
    
    const formData_class = new FormData();
    formData_class.append("id", delete_id)
    axios.post('http://cmm.ai:8088/api/delete_class?id=' + delete_id)
        .then(
            (response) => {
                console.log(response);
                // 在请求成功后重新加载页面
                location.reload();
            })
        .catch((error) => console.log(error))

});