Jquery ajax post请求发送多个请求

Jquery ajax post请求发送多个请求,jquery,datatables,Jquery,Datatables,我有一个datatables表,当点击它时,我会看到一个带有下拉列表和更新技术按钮的模式对话框。当我第一次单击更新技术时,它工作正常。但是当我不止一次尝试时,我也会收到上一个请求。换句话说,当我尝试为另一项技术更新另一项活动时,假设我为一项技术更新了一项活动。它用当前技术更新了先前的请求和新的请求 $("#dataTables-example").on('click', 'tr', function(event){ event.preventDefault

我有一个datatables表,当点击它时,我会看到一个带有下拉列表和更新技术按钮的模式对话框。当我第一次单击更新技术时,它工作正常。但是当我不止一次尝试时,我也会收到上一个请求。换句话说,当我尝试为另一项技术更新另一项活动时,假设我为一项技术更新了一项活动。它用当前技术更新了先前的请求和新的请求

    $("#dataTables-example").on('click', 'tr', function(event){
                event.preventDefault();                    
                var nTds = $('td', this);
                console.log(nTds);
                //example to show any cell data can be gathered, I used to get my ID from the first coumn in my final code
                var sBrowser = $(nTds[0]).text();
                var sGrade = $(nTds[4]).text();
                var dialogText="The info cell I need was in (col2) as:"+sBrowser+" and in (col5) as:"+sGrade+"" ;
                var targetUrl = $(this).attr("href");
                $.getJSON('/workorder/' + sBrowser, function(data) {
                console.log(data);
                var template = "<table class=table><thead><tr><th>Line</th><th>Product</th><th>Status<th>Price</th><th>Access</th><th>Serial</th><th>Callback</th><th>Delete</th></thead><tbody></tbody><tr></tr>{{#lines}}<td>{{Line #}}</td><td>{{Product}}</td><td>{{Status}}</td><td>{{price}}</td><td>{{accessCard}}</td><td>{{Serial #}}</td><td>{{callback}}</td><td><button class='btn btn-primary btn-xs' type='button'>Delete</button></td><tr>{{/lines}}<tfoot><tr><td></td><td></td><td></td><td></td><td></td><td>Total</td><td></td><td></td></tfoot></table>";
                var html = Mustache.to_html(template, data);

                $('.modal-body').html(html);
                $('#myModal').modal()
                $.fn.editable.defaults.ajaxOptions = {type: "PUT"};
                $.fn.editable.defaults.mode = 'inline';

                });
$('#updateTech').click(function() { 
    event.preventDefault();
    $.ajax({
        url: '/workorders/' + sBrowser,
        type: 'POST',
        data: {'techId':$('#options').val(),'activityNumber':sBrowser}, // An object with the key 'submit' and value 'true;
        success: function (result) {
            console.log(sBrowser);
            console.log($('#options').val());
        }
    }); 
});
});
$(“#数据表示例”)。在('click','tr',函数(事件){
event.preventDefault();
var nTds=$('td',此);
控制台日志(nTds);
//示例显示可以收集任何单元格数据,我使用从最终代码的第一列获取ID
var sBrowser=$(nTds[0]).text();
var sGrade=$(nTds[4]).text();
var dialogText=“我需要的信息单元格在(col2)中显示为:“+sBrowser+”,在(col5)中显示为:“+sGrade+”;
var targetUrl=$(this.attr(“href”);
$.getJSON('/workorder/'+sBrowser,函数(数据){
控制台日志(数据);
var template=“LineProductStatusPriceAccessSerialCallbackDelete{{{{lines}}}{{Line}}{{Product}}{{Status}}{{price}}{{accessCard}{{Serial}{lines}}}{callback}{{Line}}{Product}}}{Status}}{;
var html=Mustache.to_html(模板、数据);
$('.modal body').html(html);
$('#myModal').modal()
$.fn.editable.defaults.ajaxOptions={type:“PUT”};
$.fn.editable.defaults.mode='inline';
});
$('#updateTech')。单击(函数(){
event.preventDefault();
$.ajax({
url:'/workorders/'+sBrowser,
键入:“POST”,
数据:{'techId':$('#options').val(),'activityNumber':sBrowser},//一个键为'submit'且值为'true'的对象;
成功:功能(结果){
控制台日志(sBrowser);
log($('#options').val());
}
}); 
});
});
有人能帮我吗


谢谢。

听起来您需要在关闭模式时添加一个remove()方法,这样它就会消失

我不熟悉这个Mustache代码,但是我的想法是在model中添加一个close函数,这样它就会破坏添加的dom。核心问题是,最终会在dom中添加两个附加项,其中包含选项列表,这些选项列表会将dom添加到DB的post函数中

所以

在关闭事件时,启动清空html的函数

 $('.modal-body').html('');

我不确定如何使用这个插件实现这一点

谢谢你给我指明了正确的方向。解开更新按钮就成功了<代码>$(“#closemodal”)。单击(函数(){$(“#updateTech”)。解除绑定(“单击”);}