开发者

ajaxComplete function "loader" running once

开发者 https://www.devze.com 2023-02-03 08:02 出处:网络
here is the code I\'m using: $(function() { $(\".fav\").click(function() { var page= $(\'#page\').attr(\'value\');

here is the code I'm using:

$(function() {
    $(".fav").click(function() {
        var page     = $('#page').attr('value');  
        var user     = $('#user').attr('value');
        var time     = $('#time').attr('value'); 
        var info = "page="+ page +"& user="+ user +"& time="+ time;
        $("#loading").html('<im g src="loader.gif" />');

        $.ajax({
            type: "POST",
            url: "favorite.php",
            data: info, 
            success: function() {
                $("#loading").ajaxComplete(function(){}).slideUp();
                $('#fav').fadeOut(200).hide();
                $('#unfav').fadeIn(200).show();
            }
        });
        return false;
    });
});
</script>

<script type="text/javascript" >
$(function() {
    $(".unfav").click(function(){
        var page     = $('#page').attr('value');  
        var user     = $('#user').attr('value'开发者_Go百科);
        var info = "page="+ page +"& user="+ user;
        $("#loading").html('<im g src="loader.gif" />');

        $.ajax({
            type: "POST",
            url: "notfavorite.php",
            data: info, 
            success: function(){
                $("#loading").ajaxComplete(function(){}).slideUp();
                $('#unfav').fadeOut(200).hide();
                $('#fav').fadeIn(200).show();
            }
       });
       return false;
    });
});

Everything is working fine, it acts as a "like" "follow" button, the only problem is that the ajaxComplete() function only runs once.

Cheers!


$(function(){
  $(".fav").click(function(){
    var page     = $('#page').attr('value');  
    var user     = $('#user').attr('value');
    var time     = $('#time').attr('value'); 
    var info = "page="+ page +"& user="+ user +"& time="+ time;        
    $("#loading").html('<im g src="loader.gif" />');
    $('#follow').hide();
    $.ajax({
      type: "POST",
      url: "favorite.php",
      data: info, 
      success: function(){
        $('#loading').empty();
        $('#remove').fadeIn(200).show();
      }
    });
    return false;
  });
})();

same for .unfav

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号