简体   繁体   English

jQuery AJAX setTimeout回调

[英]jQuery AJAX setTimeout callback

I am writing a game and I am stuck on this part... During combat I have a dice roller which has to be loaded via Ajax and the issue i continue to run in to is how to call the roller then wait for the user to roll then keep going in combat i feel like its just out of my reach. 我正在写游戏,但又卡在这部分上...在战斗中,我有一个骰子滚轴,必须通过Ajax加载,而我继续遇到的问题是如何调用滚轴,然后等待用户然后继续战斗,我觉得这超出了我的能力。 i have tried... 我努力了...

function continuecombat(enemyid,character,action)
{////gets the modal
    $.ajax({
        url: url,
        type:"post",
        data:{dice:"",reason:action,characterid:cid,eid:enemyid},
        success: function(newHTML, textStatus, jqXHR) 
        {
            $(newHTML).appendTo('body').modal({
                escapeClose: false,
                clickClose: false,
                showClose: false  
            }); 
        }
    });
    getcontinueroll(enemyid,character);
}
function getcontinueroll(enemyid,character)
{ ///// checks to see if the dice has been rolled
    $.ajax({
        url: url,
        type:"post",
        data:{action:"getroll",charid:cid},
        success: function(roll) 
        {
            if(roll== "0")
            {
                setTimeout(function() 
                 {
                      getcontinueroll(enemyid,character)
                 },2000);
            }
            else
            {
                getcontinueactions(roll,enemyid,character);
            }
        }
    }); 
}

and then marking the dice as rolled 然后将骰子标记为滚动

function after_roll(notation, result) 
{
    $.ajax({
        url: url,
        type:"post",
        data:{"action":"markroll","charid":cid,"roll":result},
        success: function(newHTML) 
        {

        }
    });
}

but this causes extra ajax calls continuing after the combat is over. 但这会导致额外的ajax调用在战斗结束后继续。 The roller has to stay generic as there are different types of rolls. 辊子必须保持通用,因为有不同类型的辊子。 I would appreciate any help. 我将不胜感激任何帮助。 do have access to any variable created on both the main screen and the roller 确实可以访问在主屏幕和滚轴上创建的任何变量

After days of contemplating this, the solution hit me in the face i am already passing the information to the modal so i just moved the function call to roll resolution and bypassed the ajax call that was checking for the roll. 经过几天的思考,面对的解决方案令我震惊,因为我已经将信息传递给模态了,所以我只是将函数调用移至滚动分辨率,并绕过了检查滚动的ajax调用。 Sometimes the best way to solve a problem is walk away. 有时,解决问题的最佳方法就是走开。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM