开发者

AJAX periodical check until conditions are met

I have an application whic开发者_运维问答h communicates with mobile phone gate. User has to send SMS/Text to number and then needs to wait for confirmation.

I'd like to know how to check for response until user receives it. How can I call AJAX check every 10 seconds?


You can use a spin-off of a long polling technique.

Basically just set a setInterval function that will fire every 10 seconds. The callback function of that will be your ajax call. Make the ajax function check the value of a variable, presumably one that is a boolean representing whether or not the text has been confirmed.

setInterval(function() {
    if(!condition) {
        //ajax functionality again
    }
}, 10*1000);

The reason why I have the !condition part is because I dont want the function to execute all the way if the condition has already come back true, thus confirming the text.

You should then kill the interval function too.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜