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


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

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


<div id="body">


        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
                url: "ajax_cron.php",
                type: 'POST',
                dataType: 'json',
                data: {update_id : array_items[i]['ids']},
                success: function (data) {
                    // kreipimąsis pavyko 
                        updated_items += 1;
                    $("#body").html(updated_items + " iš " +array_items.length + " updeitinta sėkmingai");                   
                }, error: function(e){


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.




  • ¥20 请问这种量表怎么用spss量化分析(作为中介模型的因变量
  • ¥55 AD844 howland电流源如何驱动大额负载
  • ¥15 C++ /QT 内存权限的判断函数列举
  • ¥15 深度学习GFnet理解问题
  • ¥15 单细胞小提琴堆叠图代码
  • ¥50 升级strust2版本到2.3.15.1后使用ognl3.0.6.jar windows环境中没有问题,但部署到linux环境报错
  • ¥15 vue页面,node封装接口
  • ¥15 求TMS320F280039C工程模板!
  • ¥15 delphi+fastreport实现分组补空打印问题
  • ¥15 使用python把两台mysql数据库服务器数据导出和导入