2017-05-29 163 views
1

请帮我,现在我可以删除从我的数据库中的数据,但在屏幕上它不会自动消失如何在点击按钮后自动加载div?

Here`s我的代码:

$(document).on('click','.remove',function(e){ 
    var x = document.getElementsByTagName('input'); 
    var a = $(this).attr('data'); 
    $.ajax({ 
     url:"http://localhost/scorecard/wp- 
     content/themes/twentyseventeen/ajax/submit.php?function=removeScore", 
     type:"post", 
     data:{ id:a }, 
     success: function(data){ 
     alert("Success"); 
     $('#formUpdateScore').append(data); 
     } 
    }); 
    }) 

这是我的html:

<form id="formUpdateScore"> 
    <?php 
     include(dirname(__FILE__).'/template-parts/php/add_variable.php'); 
     $var = new variable(); 
     $connection = $var->connect(); 
     $var->gi_id = $_POST['id']; 
     $GLOBALS['x'] = $var->gi_id; 
     $query = "SELECT * FROM business_variable WHERE company_id = ".$var->gi_id; 
     $result = mysqli_query($connection,$query); 
     while($row = mysqli_fetch_array($result)){ 
     ?> 
     <div class="col-md-4 col-md-offset-1 aligntop"> 
      <div class="varName"> 
      <div class="col-md-8" style="padding:0;"> 
       <span class="variable" name="<?php echo $row['variable_name']?>" value="<?php echo $row['var_id']?>"><?php echo $row['variable_name']?></span> 
      </div> 
      <div class="col-md-4" style="padding-left: 0;"> 
       <input type="number" name="name[]" style="width: 55%;height: 40px;float: left;padding: 5px 4px;" class="score" id="getScore" data="<?php echo $row['var_id']?>" value="<?php echo $row['variable_score']?>"/> 
       <input type="button" data="<?php echo $row['var_id']?>" class="remove" value="-"/> 
      </div> 
      </div> 
     </div> 
     <?php 
     } 
mysqli_close($connection); ?> 
</form> 

回答

2
success:function(response){ 
//on success, hide element user wants to delete. 
$('.classname').fadeOut(); //use element class name or id 

} 

OR

success:function(response){ 
//on success, hide element user wants to delete. 
$('.classname').hide(); //use element class name or id 
} 
+0

嗯,我在表格的每一格添加动态ID –

0

让个人格代表一个分数,类名像score,像

<div class="col-md-4 col-md-offset-1 aligntop score"> 

然后在去除成功函数找到closest得分股利和remove的元素。

$(document).on('click','.remove',function(e){ 
    var inp = $(this); 
    var a = inp.attr('data'); 
    $.ajax({ 
     url:"http://localhost/scorecard/wp-content/themes/twentyseventeen/ajax/submit.php?function=removeScore", 
     type:"post", 
     data:{ id:a }, 
     success: function(data){ 
      alert("Success"); 
      inp.closest('.score').remove(); 
     } 
    }); 
}); 

问候