成功后如何在ajax中添加bootstrap切换按钮?

时间:2017-09-10 13:39:04

标签: ajax twitter-bootstrap bootstrap-4

我想在成功后使用ajax中的bootstrap切换按钮。有什么办法吗?我尽力实现但不能完全实现它。

<script>
$(document).ready(function(){
  $(".btn-primary").click(function(){
    $(".collapse").collapse('toggle');
  });
});
</script>

<script type="text/javascript">
    $('.other_chart').live("click",function(){
        //e.preventDefault();
        var userid2= $(this).attr("id").split('_').pop();
        $.ajax({
        type: "POST",
        async: false,
        url: "index.php",
        data: "userid="+ userid2,
        cache: false,
        //beforesend: function(){$(".podar").show();},
        success: function(html) {
              //$("#loader_"+userid1).hide();
              $("#wholeinf1_"+userid2).toggle();
                  $("#wholeinf_"+userid2).empty().append(html);
            }
        });
    });
</script>

    <div id="wholeinf1_<?php echo $res['userid']; ?>" style="height:auto; width:auto; display:none;">
      <div id="wholeinf_<?php echo $res['userid']; ?>" style="height:auto; width:auto;">
      </div>
    </div>

<div style="display:block;">
 <button class="other_chart" id="chart_<?php echo $res['userid']; ?>" type="button" class="btn btn-primary">View Chart</button>
</div>

1 个答案:

答案 0 :(得分:0)

您需要在dataType: 'html'请求中添加$ajax

$("#wholeinf1_"+userid2).toggle();更改为$("#wholeinf1_"+userid2).show();