lbfeng
V2EX  ›  Flask

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

  •  
  •   lbfeng · Dec 2, 2015 · 3305 views
    This topic created in 3815 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
        1
    Moker  
       Dec 2, 2015   ❤️ 1
    点击 follow 如果关注成功 更改 button 的值 如果不成功给出相应提示
    取消关注同理
    lbfeng
        2
    lbfeng  
    OP
       Dec 2, 2015
    @Moker 在 ajax 的 success 和 error 里搞?
    qiayue
        3
    qiayue  
    PRO
       Dec 2, 2015   ❤️ 1
    @lbfeng 在 ajax 的 success 里搞
    answeryou
        4
    answeryou  
       Dec 2, 2015   ❤️ 1
    vm.follow = function() {
    }
    answeryou
        5
    answeryou  
       Dec 2, 2015
    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   ·   Solana   ·   3608 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 35ms · UTC 10:38 · PVG 18:38 · LAX 03:38 · JFK 06:38
    ♥ Do have faith in what you're doing.