lbfeng
V2EX  ›  Flask

如何实现类似 twitter 的 follow 和 unfollow button

  •  
  •   lbfeng · Dec 2, 2015 · 3714 views
    This topic created in 3997 days ago, the information mentioned may be changed or developed.

    已经写了有两个 view function 可以处理 follow, unfollow 。然后点击 button 触发 ajax 吗?

    6 replies  •  2015-12-02 11:01:54 +08:00
    Moker
    Moker
    Dec 2, 2015❤️1
    1
    点击 follow 如果关注成功 更改 button 的值 如果不成功给出相应提示
    取消关注同理
    lbfeng
    lbfeng
    OP
    Dec 2, 2015
    2
    @Moker 在 ajax 的 success 和 error 里搞?
    qiayue
    qiayue
    Dec 2, 2015❤️1
    3
    @lbfeng 在 ajax 的 success 里搞
    answeryou
    answeryou
    Dec 2, 2015❤️1
    4
    vm.follow = function() {
    }
    answeryou
    answeryou
    Dec 2, 2015
    5
    vm.follow = function() {
    vm.abled = false;
    var promise = goFollow();
    promise.then(function (res) {
    vm.abled = true;
    }, function () {
    });
    };

    function goFollow() {
    var deferred = $q.defer();
    $http.post('xxx', param).then(function (response) {
    if (response.code === 200) {
    deferred.resolve(response);
    }
    });
    return deferred.promise;
    }
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   2284 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 13:17 · PVG 21:17 · LAX 05:17 · JFK 08:17
    ♥ Do have faith in what you're doing.