对于我正在处理的网站,我有以下代码。它是为了商业用途。该网站实际上是PHP,文件是index.php,因为它存在于服务器上。您可以在以下网址看到该网站:www.tradingcharts.ca。到目前为止,该网站在功能方面完美运行。还有一些功能需要添加,例如将表单数据保存到磁盘和数据验证。
我的问题是,无论何时最终用户加载网站,都会有明显的延迟。当最终用户点击表单上的提交按钮以打开帐户或登录帐户时,也会发生此延迟。延迟持续约半秒,在呈现内容之前屏幕变为空白空格。但事情是,当我在我的个人计算机上加载了我使用IIS的网站时,这种现象并不会发生;它只会在上传到异地服务器时发生。我愿意就如何纠正这个问题提出建议。请随时查看以下源代码:
T

答案 0 :(得分:0)
Found a solution. Using jquery solved the problem. Essentially it allowed me to post variables to the server without actually submitting the variables by a regular form. A snippet of the code is shown below.
<!DOCTYPE html>
<html>
<head>
<!-- https://www.w3schools.com/jquery/jquery_get_started.asp -->
<!-- google -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<!-- microsoft -->
<script src="https://ajax.aspnetcdn.com/ajax/jQuery/jquery-3.3.1.min.js"></script>
</head>
<body>
<?php
$name = $_POST['postname'];
$loaded = $_POST['postloaded'];
if ($name != null)
echo "your input is ".$name;
if ($loaded == null)
{
echo "<script>
document.addEventListener(\"DOMContentLoaded\", function(event) {
var loaded = true;
$.post('index.php', {postloaded:loaded},
function(data)
{
$('#result').html(data);
});
});
var div = document.createElement(\"div\");
div.setAttribute(\"id\", \"result\");
document.body.appendChild(div);
var form = document.createElement(\"form\");
var input = document.createElement(\"input\");
input.setAttribute(\"type\", \"text\");
input.setAttribute(\"id\", \"name\");
form.appendChild(input);
var br = document.createElement(\"br\");
form.appendChild(br);
var input = document.createElement(\"input\");
input.setAttribute(\"type\", \"button\");
input.setAttribute(\"value\", \"submit\");
input.setAttribute(\"onclick\", \"post();\");
form.appendChild(input);
document.body.appendChild(form);
function post()
{
var name = $('#name').val();
var loaded = true;
$.post('index.php', {postname:name, postloaded:loaded},
function(data)
{
$('#result').html(data);
});
}
</script>";
}
?>
</body>
</html>