weixin_33737774 2014-01-19 18:23 采纳率: 0%
浏览 25

cron-job的AJAX动作?

I tried to update so much rows with PHP that I had to make it with ajax (becouse execution time in server is too short for execute all rows). So I made a code which should call a .php file with the code inside, which updates sended ROW id in mysql table.

I have a code

<html>
<head>
    <title>Cron job!</title>
    <meta charset="UTF-8" />
    <script src="jquery.js"></script>
</head>

<html>
<body>

<div id="body">

</div>

<script>
    $(document).ready(function(){
        var array_items = <?=$table_info?>;
        var updated_items = 0;

        for(var i=0; i<array_items.length; i++){
            // pradedam kreipimąsi į kiekvieną rową jo updeitui su ajax
            $.ajax({
                url: "ajax_cron.php",
                type: 'POST',
                dataType: 'json',
                data: {update_id : array_items[i]['ids']},
                success: function (data) {
                    // kreipimąsis pavyko 
                    if(data.updated_id){
                        updated_items += 1;
                    }
                    $("#body").html(updated_items + " iš " +array_items.length + " updeitinta sėkmingai");                   
                }, error: function(e){
                    console.log(e.message);
                }
            });            
        }
    });
</script>

</body>
</html>

and it works when I open url with browser but when I make a call to this script with CRON JOB - ajax doesn't work.. So how to make it work?

  • 写回答

1条回答 默认 最新

  • weixin_33712881 2014-01-19 18:32
    关注

    Ajax is a client side technology, so it requires client (a browser) to be able to execute the script and most importantly the DOM elements which could be read by your Javascript.

    Cron Job on the other hand runs on CLI which does not know anything about the DOM when a script runs there.

    So in other words what you are trying to do is not possible with the current web technology that we have. However you can always run a server side script on cronjob but client side script, no you can not.

    评论

报告相同问题?

悬赏问题

  • ¥15 系统 24h2 专业工作站版,浏览文件夹的图库,视频,图片之类的怎样删除?
  • ¥15 怎么把512还原为520格式
  • ¥15 MATLAB的动态模态分解出现错误,以CFX非定常模拟结果为快照
  • ¥15 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
  • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET
  • ¥30 写segy数据时出错3
  • ¥100 linux下qt运行QCefView demo报错
  • ¥50 F1C100S下的红外解码IR_RX驱动问题