具有cron作业和ajax的Node.js

I wanted to schedule sending of report(chart made by javascript) via email in a weekly basis. To have that, I need to convert first the chart(made by javascript) to image using php(AJAX) and upload to the server then send it.

I'm already using node.js in my server but ajax doesn't work there. Is there's any way to get the same goal I want?


ReferenceError: XMLHttpRequest is not defined I got this error in the terminal.

Is there any error in my code?

var CronJob = require('cron').CronJob; new CronJob('10 * * * * *', function() {

ajax_request=new XMLHttpRequest;
ajax_request.onreadystatechange=function(){
    if(ajax_request.readyState==4&&ajax_request.status==200){
         console.log('You will see this message every second');
    }
};
ajax_request.open("GET","http://domain.com/test.php",true);
ajax_request.send();

}, null, true, 'Asia/Manila');

dqhdz04240
dqhdz04240 ReferenceError:未定义XMLHttpRequest我在终端中收到此错误。
大约 5 年之前 回复
doumei1772
doumei1772 是的我已经完成了cronjob和ajax的组合,但它不起作用。
大约 5 年之前 回复
dsgdhf5674
dsgdhf5674 也许是cronjob。
大约 5 年之前 回复

1个回答



为什么ajax不能与node.js一起使用? AJAX只是通过HTTP协议使用javascript发送数据,只要它们支持HTTP协议,它对它使用的后端设置没有任何限制。</ p>

您可以生成 使用node.js的图像,你不必使用PHP </ p>
</ div>

展开原文

原文

Why would ajax not work with node.js? AJAX simply sends data with javascript via the HTTP protocol, it does not have any restrictions in regards to which backend setups it works with, as long as they support the HTTP protocol.

You can generate the image with node.js, you dont have to use PHP

doue2666
doue2666 stackoverflow.com/questions/22687939/...
大约 5 年之前 回复
douba1214
douba1214 如果你知道热,从数据图像base64生成图像到node.js请分享。 我很感激。
大约 5 年之前 回复
doutong6814
doutong6814 ReferenceError:未定义XMLHttpRequest我在终端中收到此错误。 我的代码中有错误吗? var CronJob = require('cron')。CronJob; new CronJob('10 * * * * *',function(){ajax_request = new XMLHttpRequest; ajax_request.onreadystatechange = function(){if(ajax_request.readyState == 4 && ajax_request.status == 200){console.log('You 每秒都会看到此消息');}}; ajax_request.open(“GET”,“domain.com/test.php”,true); ajax_request.send();},null,true,'Asia / Manila' );
大约 5 年之前 回复
立即提问
相关内容推荐