weixin_33743248 2020-03-07 14:49 采纳率: 0%
浏览 56

Ajax转PHP循环问题

I have an issue with a continuous Ajax to PHP loop. The code (below) works absolutely fine. However I find it will run for 2, 3, or more hours or as required.. but then have an "x minute" break where it won'T run or produce any logs... before once "again" resuming for 2, 3 or more hours.

$.ajax({
    async: false,
        type: "POST",
        url: ajaxURL,
        dataType: 'json',
        data: {functionname: 'conditionTrade', arguments: [c_piars, c_timeframes, usd_amount ,stop_loss, stop_loss_min, stop_loss_max]},
// post to php and check condition
        success: function (data) {
            if( !('error' in data) ) {
                var results = data["result"];
                if (results) {
                    $( "#tradelog" ).load( "tradelog.html" ); // <--- produce a log
                    var pft = c_piars+"profitloss.txt";
                    $( "#profit" ).load( pft );
                    checkCondition(); 
// recursion call to this same method ie. check again
                }
                else {
                    console.log(data.error);
                }
            var objDiv = document.getElementById("tradelog");
            objDiv.scrollTop = objDiv.scrollHeight;
        }},
        error: function(jqXHR, textStatus, errorThrown) {
            console.log("Error[refresh]: " + textStatus);
            console.log(jqXHR);
            checkCondition(); 
// recursion call to this same method ie. check again
         },

    });

Please can somebody advise as to why this loop is randomly breaking, and then continuing on its own. The loop is intended to retrieve candlestick data (approximately every 5 seconds), then perform some Technical Analysis checks, before finally.. outputing a log of the whether the TA conditions were found. The code runs fine. However it's almost as if when I'm not physically on the browser page, then, it may randomly stop working for 15 minutes or a random time, before resuming on its own. (Hence I may get 2,3,4,5 hours of continuous checks, then a random dropout of 30 minutes to 2 hours, before resuming checks for x hours). What am I missing? I've looked into using different browsers, browser resources, internet connections, php timeouts etc. but this one is really head scratching. Thank you if you can help.

Ps. With a previous version I used to used the ajax- settimeout (5000) looping method, rather than the "recursion call to this same method" shown. This would literally run all day night without any dropping out - but I found that it would race itself from time to time, not waiting for the previous loop to complete. And therefore I might find 2 or 3 log entries for the same loop. How might I stabalize this loop to perform as I would like ? Thanks.

  • 写回答

1条回答 默认 最新

  • python小菜 2020-03-17 11:38
    关注

    If you have similar: How can I make setInterval also work when a tab is inactive in Chrome?

    If your script/jsfiddle is logging to the console, simply route it to the page title eg. document.title= 'your setInterval output'; ..so you'll better be able to detect what your interval loop is doing as you switch tab etc.

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置