我有一个简单的代码,每5秒将ajax发送到Arduino以获取数据。现在,我添加setTimeout以每5秒刷新一次浏览器。
我想知道是否可以在不打开chrome或浏览器的情况下在后台运行此代码。或者如果没有其他方法可以快速从Arduino获取数据。我在这台计算机上安装了Apache作为我的服务器。
<?php
?>
<script src = "https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js" > </script>
<script>
setTimeout('window.location.reload();', 5000);
$.ajax({
type: 'POST',
url: 'php/proccess.php',
data: { type: "Send"},
dataType: "json",
success: function(response) {
console.log(response);
$.each(response,function(key, value)
{
//console.log(value);
$.ajax({
url: 'http://' + value[0],
type: 'GET',
dataType: 'json',
data: {
"do": "Send",
},
contentType: 'application/json',
success: function (data) {
console.log(data);
if(data){
$.ajax({
type: 'POST',
url: 'php/proccess.php',
data: { type: "received", "response" : data},
dataType: "json",
success: function(response) {
console.log(response);
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 500) {
alert('Internal error: ' + jqXHR.responseText);
} else {
console.log(jqXHR);
}
},
});
}
},
});
});
},
error: function (jqXHR, textStatus, errorThrown) {
if (jqXHR.status == 500) {
alert('Internal error: ' + jqXHR.responseText);
} else {
console.log(jqXHR);
}
},
});
</script>