我在点击事件中使用
Jquery Ajax函数从数据库中获取数据.
此功能正常工作并显示数据.
但是加载数据需要时间,因此我想在获取数据的同时放置加载图像.
我用这种方法来做
<script type="text/javascript"> jQuery(function($) { $(document).ready(function() { $("#imgs").hide(); $(".letter").bind('click',function(){ $("#imgs").fadeIn(); var val = $(".letter").val; var site = '<?PHP echo site_url(); ?>'; $.ajax({ url: site+'/wp-content/themes/premiumnews/newContent.PHP?letter='+$(this).html(),success:function(data){ $("#imgs").hide(); $("#content1").html(data); } }); }); }); }); </script>
当我点击按钮时,会出现加载图像,但成功后图像应该消失,在我的情况下它仍然存在
解决方法
这是我过去一直使用的:
$('#loading_div').hide().ajaxStart(function(){ $(this).show(); }).ajaxStop(function() { $(this).hide(); });