jQuery, Is there a way to bind events reloading a script?

By JDLK7

I have an ajax function that gets a table body from laravel and reloads it. Each row has a checkbox input which has events from a template script. Moreover this script changes the checkbox style. Everything works fine until I call this function. Then, the table reloads and the checkbox style and events stop working.

I don’t know how to solve this manually, so I tried to reload these scripts (with “jQuery.getScript()”) but it doesn’t work. Is there any way to reload an entire script? or do I have to bind the events with “on()”?

HTML

<tbody>
<?php $i=0; foreach($content as $file) : ?>
    <tr class="<?php if($i%2==0) echo 'even'; else echo 'odd'; ?> pointer">
        <td class="hidden-cell">{{ $file->id }}</td>
        <td style="width: 60%;">
            <span style="line-height: 20px;"><i class="{{ fileIcon($file->extension) }}"></i> {{ $file->name }}</span>
            <input type="text" class="hidden-cell edit-name" placeholder="{{ $file->name }}">
        </td>
        <td style="text-align: center;">
            @if( $file->type == 'archive')
                {{ getSizeString($file->size) }}
            @endif
        </td>
        <td style="text-align: center;">{{ $file->extension }}</td>
        <td style="text-align: center;">{{ $file->created_at }}</td>
        </td>
        <td class="a-center">
            <input type="checkbox" class="flat" name="table_records">
        </td>
    </tr>
<?php $i++; endforeach; ?>
</tbody>

jQuery

function loadFolder() {
    $.ajax({
        type: "GET",
        url: "/drive/load",
        data: { id_folder: clickedId },
        dataType: "html",
        success: function(response){
            $('tbody').replaceWith(response);
            $('.pointer').on('dblclick', dbclickFile);
            jQuery.getScript('/vendors/jquery/dist/jquery.min.js');
            jQuery.getScript('/vendors/iCheck/icheck.min.js');
            jQuery.getScript('/build/js/custom.min.js');
        },
        error: function(jqXHR, textStatus, errorThrown) {
            var newDoc = document.open("text/html", "replace");
            newDoc.write(jqXHR.responseText);
            newDoc.close();
        }
    });
}

Source: Stack Overflow

    

Share it with your friends!

    Fatal error: Uncaught Exception: 12: REST API is deprecated for versions v2.1 and higher (12) thrown in /home/content/19/9652219/html/wp-content/plugins/seo-facebook-comments/facebook/base_facebook.php on line 1273