Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/441.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript jQuery Selective()通过ajax发布,其中选择在发布之前循环其历史记录_Javascript_Jquery_Ajax - Fatal编程技术网

Javascript jQuery Selective()通过ajax发布,其中选择在发布之前循环其历史记录

Javascript jQuery Selective()通过ajax发布,其中选择在发布之前循环其历史记录,javascript,jquery,ajax,Javascript,Jquery,Ajax,我有一个表,用户可以选择多行。选定的行具有唯一的ID,然后将其聚合为字符串并发布到php文件。除了我有一个问题外,一切都很好。如果选择了行,则多次重新选择不会发布选择的最后状态。因此,当我查看日志时,我基本上看到: 14_629_2 view.php:541 14_629_15 view.php:541 14_629_2 view.php:541 14_629_15 view.php:541 14_629_2;14_629_15 view.php:541 14_629_15 view.php:5

我有一个表,用户可以选择多行。选定的行具有唯一的ID,然后将其聚合为字符串并发布到php文件。除了我有一个问题外,一切都很好。如果选择了行,则多次重新选择不会发布选择的最后状态。因此,当我查看日志时,我基本上看到:

14_629_2 view.php:541
14_629_15 view.php:541
14_629_2 view.php:541
14_629_15 view.php:541
14_629_2;14_629_15 view.php:541
14_629_15 view.php:541
顺便说一下,这是两排。因此,最后一个状态可以是两行选择
14_629_2;14_629_15 view.php:541
,但出于某种原因,它会发布
14_629_15 view.php:541
。这就好像它保留了所做选择的缓存或历史记录,然后在一个spur中循环和转储所有内容。。有时会搞砸

我基本上需要它只跟踪当前选择,没有历史记录


我使用的代码:

  <script> 
    $('#t1').selectable({
      filter:'tbody tr',
      stop: function(event, ui){
      var map = $( this ).find( ".ui-selected" ).map(function() {return this.id;}).get().join(";");
      // var result = $( "#plate" ).empty().html(map);
      $('#batch_send').click(function (){
         $(function() {
            $.ajax({
               url: 'batch_send.php',
               type: 'POST',
               data: 'variable='+map,
               success: function(data) {
                  $('.display_div').html(map);
                  console.log(map); 
               }
            });
         });
      });
      }
    });
    </script>

$('#t1')。可选({
过滤器:'tbody tr',
停止:功能(事件、用户界面){
var map=$(this.find(“.ui selected”).map(函数(){returnthis.id;}).get().join(;”;
//var result=$(“#plate”).empty().html(map);
$(“#批处理发送”)。单击(函数(){
$(函数(){
$.ajax({
url:'batch_send.php',
键入:“POST”,
数据:“变量=”+映射,
成功:功能(数据){
$('.display_div').html(地图);
控制台日志(map);
}
});
});
});
}
});
我是javascript新手,所以这肯定是个明显的错误…

解决方案:

它循环的原因是因为ajax请求位于函数中

所以我重写了代码,使它更简单一些

var map;
$("#t1").selectable({
  filter:'tbody tr',
  cancel: 'a, #slct_ignore, thead',
      stop: function(event, ui) {
      map = $(this).find( ".ui-selected" ).map(function() {return this.id;}).get().join(";");
    }
});

$("#batch_send").click(function() {
    $.ajax({
            url: 'batch_send.php',
            type: 'POST',
            data: 'variable='+map,
            success: function(data) {
                                    $("#plate").html(map);
                                    $(".display_div").html(map);
                                    }
          });
});