JQuery: button inside Modal window JQuery: button inside Modal window flask flask

JQuery: button inside Modal window


var table= $('#example').DataTable();var tableBody = '#example tbody';var form = new FormData();

Use this code inside

$(document).ready(function() { });  

And remove the below script

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>


the script in the header is actually

<script type="text/javascript" src="https://cdn.datatables.net/v/dt/dt-1.10.16/datatables.min.js"></script>

So you are suggesting :

var table= $('#example').DataTable();    var tableBody = '#example tbody';    var form = new FormData();    $(document).ready(function() { });    $(tableBody).on('click', 'tr', function () {        var cursor = table.row($(this));//get the clicked row        var selected_id = cursor.data()[0];// this will give the id in the current row.        $('#myModal').on('shown.bs.modal', function (event) {            $("#testbutton").trigger("click");        });        $("#newBtn").on("click",function(){            form.set("action", "select_id");            form.set("selected_id", selected_id);            var settings = {                "url": "http://127.0.0.1:5000/test",                "method": "POST",                "timeout": 0,                "processData": false,                "mimeType": "multipart/form-data",                "contentType": false,                "data": form            };            $.ajax(settings).done(function (response) {                console.log(response);            });        });    });

This still doesn't solve it on my end: when you select row 1 and then row 2 the button will send 2 posts instead of only 1 desired post with row 2 as data