加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php – 成功函数中的jQuery ajax函数如果存在页面重定向则被忽略

发布时间:2020-12-13 22:24:17 所属栏目:PHP教程 来源:网络整理
导读:我有一个ajax请求,我想在重新加载页面之前完成一些jQuery动画.问题是我的动画功能“flyToChart”完全被忽略,页面立即重新加载.如果我注释掉重新加载的页面代码,动画效果很好.如何让我的动画先运行,然后重新加载页面甚至重定向到另一个页面?这是我的代码: j
我有一个ajax请求,我想在重新加载页面之前完成一些jQuery动画.问题是我的动画功能“flyToChart”完全被忽略,页面立即重新加载.如果我注释掉重新加载的页面代码,动画效果很好.如何让我的动画先运行,然后重新加载页面甚至重定向到另一个页面?这是我的代码:

jQuery.ajax({
            url: 'session/phpSession.php',type: 'POST',data: {
                ProductDescription: productDescription,ProductPrize: productPrize,ProductSize: productSize,ProductId: productId,ProductCount: productListJson.length,ProductSmallImage: productSmallImg,ProductQuantity: productQuantity,ProductUniqueId: idGen.getId(),ProdId: prodId,},success: function() {
                flyToCart(reload);
            },error: function(xhr,textStatus,errorThrown) {
                console.log(textStatus + " " + xhr + " " + errorThrown );
            }
        });

function flyToCart(reload) {
    $('html,body').animate({
        'scrollTop' : $(".cart_anchor").position().top
    });

    var itemImg = $('.productBigImageContainer').find('img');
    flyToElement($(itemImg),$('.cart_anchor'));

    reload();
}

function flyToElement(flyer,flyingTo) {
    var $func = $(this);
    var divider = 3;
    var flyerClone = $(flyer).clone();
    $(flyerClone).css({position: 'absolute',top: $(flyer).offset().top + "px",left: $(flyer).offset().left + "px",opacity: 1,'z-index': 1000});
    $('body').append($(flyerClone));
    var gotoX = $(flyingTo).offset().left + ($(flyingTo).width() / 2) - ($(flyer).width()/divider)/2;
    var gotoY = $(flyingTo).offset().top + ($(flyingTo).height() / 2) - ($(flyer).height()/divider)/2;

    $(flyerClone).animate({
        opacity: 0.4,left: gotoX,top: gotoY,width: $(flyer).width()/divider,height: $(flyer).height()/divider
    },700,function () {
        $(flyingTo).fadeOut('fast',function () {
            $(flyingTo).fadeIn('fast',function () {
                $(flyerClone).fadeOut('fast',function () {
                    $(flyerClone).remove();
                });
            });
        });
    });
}

function reload()
{
    window.location.reload();
}

解决方法

看看下面的代码::

jQuery.ajax({
            url: 'session/phpSession.php',success: function() {
                flyToCart();               
            },errorThrown) {
                console.log(textStatus + " " + xhr + " " + errorThrown );
            }
        });

function flyToCart() {
    $('html,$('.cart_anchor'));
   window.location.reload();
}

function flyToElement(flyer,function () {
                    $(flyerClone).remove();
                });
            });
        });
    });
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读