jQuery在AJAX查询后不工作

时间:2016-07-09 06:04:18

标签: javascript jquery html ajax

我的jQuery代码有问题。 我显示隐藏的div,当鼠标悬停此div兄弟时,会显示。 但是当调用我的AJAX函数时,jQuery不起作用。

<div class="parent">
     <div class="theDiv" style="display:none">
     </div>
     <div class="sibling">
     </div>
</div>
$('.sibling').hover(function(){
  $(this).parent().find('.theDiv').fadeIn('fast');
});

$('.catFilterSelect').change(function(){
    $.ajax({
    url:"load_data.php",
    method:"POST",
    data:{
      reg:a,
      price:b,
      type:c,
      subject:d,
      city:e,
      typeSubject:typeSubject
    },
    dataType:"text",
    success:function(data){
      $('.catPostsBox .catPost').remove();
      $('.catPostsBox').append(data);
    }
  });
})

此脚本在AJAX之前有效,但在此之后无法正常工作

1 个答案:

答案 0 :(得分:0)

<div class="parent">
     <div class="theDiv" style="display:none">
     </div>
     <div class="sibling">
     </div>
</div>
<script>
$(function(){
     $('.sibling').hover(function(){
           $(this).parent().find('.theDiv').fadeIn('fast');
     });
});
or -- both are same
$(document.ready(function(){
     $('.sibling').hover(function(){
           $(this).parent().find('.theDiv').fadeIn('fast');
     });
});

</script>
<script>
$(function(){
$('.catFilterSelect').change(function(){
    $.ajax({
    url:"load_data.php",
    method:"POST",
    data:{
      reg:a,
      price:b,
      type:c,
      subject:d,
      city:e,
      typeSubject:typeSubject
    },
    dataType:"text",
    success:function(data){
      $('.catPostsBox .catPost').remove();
      $('.catPostsBox').append(data);
    }
  });
})
)};
</script>