小编bad*_*bye的帖子

javascript:如何中止$ .post()

我有post方法,如下所示:

$(".buttons").click(function(){
  var gettopic=$.post("topic.php", {id: topicId}, function(result){
  // codes for handling returned result

  });
})
Run Code Online (Sandbox Code Playgroud)

当点击一个新按钮时,我试图中止旧帖子:所以我很累

$(".buttons").click(function(){
    if (gettopic) {
        gettopic.abort();
    }
    var gettopic=$.post("topic.php", {id: topicId}, function(result){
         // codes for handling returned result
    });
})
Run Code Online (Sandbox Code Playgroud)

但这不起作用.所以我想知道如何解决这个问题?

html javascript ajax jquery

7
推荐指数
1
解决办法
2799
查看次数

Javascript:如何编写和调用递归函数?

在我为用户检索帐户之前,我需要调用一个函数来发布帐户ID.在该函数中,我需要检查检索到的帐户是否已存在于用户端,如果存在,则增加查询ID并重新运行该函数,直到检索到的帐户对用户来说是新的.

由于函数会调用自身,所以我想我正在做的是在我的生活中编写我的第一个递归函数.

我试过了:

<script>
    function updateAcc(maxVal) {

        $.post("accountUpdate.php", {maxVal:maxVal}, function(result){
            // get the retrieved account ID
            var result=$(result);
            pa.replaceWith(result);
            var resultid=result.attr("data-topic-id");
            var testlength=$('*[data-topic-id="'+resultid+'"]').length;
            // check if retrived account already exists on user's page
            // if exists alraedy, increase the query ID, run the function again, retrieved new account ID,until there's no same accounts on users' side
            if(testlength>1) {
                maxVal++;
                updateAcc();
            }

            // alert(resultid);
        })
    }
    // envoke the function
    updateAcc(maxVal)
</script>
Run Code Online (Sandbox Code Playgroud)

javascript recursion jquery

-1
推荐指数
1
解决办法
1292
查看次数

标签 统计

javascript ×2

jquery ×2

ajax ×1

html ×1

recursion ×1