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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵