向 HTML 页面添加查询

Adding a query to a HTML Page

我用 HTML 和 CSS 为我的服务器构建了一个状态页面,而不是每次其中一个出现故障时更新服务器状态,我想知道是否可以添加每 10 米左右查询一次服务器的 IP,如果查询失败,将状态按钮变为红色。

这是我正在处理的内容:https://status.floridastaterp.org

非常感谢任何帮助!

谢谢。

你可以不使用 PHP,为此使用 javascript 并进行 ajax 调用:

var xhttp = new XMLHttpRequest();
  xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
     // You change the status of button
    }
  };
  xhttp.open("GET", "ajax_info.txt", true);
  xhttp.send();

并且每 10 分钟调用一次,将您的函数扭曲为:

setTimeout(request(),1000);

function request(){
            if(response == true){
                // This makes it unable to send a new request 
                // unless you get response from last request
                response = false;
                var req = $.ajax({
                    type:"post",
                    url:"https://status.floridastaterp.org"
                });

                req.done(function(){
                    console.log("Request successful!");

                    // This makes it able to send new request on the next interval
                    response = true;
                });
            }

            setTimeout(request(),1000);
        }

        request();