简体   繁体   English

在同一个Web html页面中获得结果

[英]Get result in the same Web html page

I m running out of idea to execut my html/php web page. 我没有想法来执行我的html / php网页。

Here is the scenario : 这是场景:

From a html web page on body section I load a php script wich retrieve data from mysql db in present it in table then return it in the section in the initial web page. 从主体部分的html网页我加载一个php脚本,它从mysql db中检索数据,然后在表格中返回它,然后在初始网页的部分中返回它。 When I got this table there is a link on Id (first column) which suppose by clicking on it give info in an another section on the same page BUT it DOES NOT. 当我得到这个表时,在Id(第一列)上有一个链接,通过点击它可以在同一页面上的另一个部分给出信息,但它没有。 It shows it in another web page the info. 它在另一个网页上显示了该信息。

Here is the main html code : 这是主要的HTML代码:

<html>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://www.w3schools.com/w3css/w3.css">
<head>
<style>
#header {
    background-color:black;
    color:white;
    text-align:center;
    padding:5px;
}
#section {
    width:100%;
    float:left;
    padding:5px;         
}
#footer {
    background-color:black;
    color:white;
    clear:both;
    text-align:center;
    padding:5px;    
    text-shadow: 1px 1px;   
}
</style>
<script>
function getStudentStatus(Id) {
    if (Id == "") {
        document.getElementById("StuStat").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("StuStat").innerHTML = xmlhttp.responseText;
            }
        }
        console.log("looking for :"+Id);
        xmlhttp.open("GET","getStudentStatus.php?StudentId="+Id,true);
        xmlhttp.send();
    }
}
function getStudentInfo(Id) {
    if (Id == "") {
        document.getElementById("StuInfo").innerHTML = "";
        return;
    } else { 
        if (window.XMLHttpRequest) {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp = new XMLHttpRequest();
        } else {
            // code for IE6, IE5
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange = function() {
            if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
                document.getElementById("StuInfo").innerHTML = xmlhttp.responseText;
            }
        }
        console.log("looking for :"+Id);
        xmlhttp.open("GET","getStuInfo.php?StudentId="+Id,true);
        xmlhttp.send();
    }
}

var intShowResult = setInterval(function() {getStudentStatus("q") },60000);

</script>
</head>
<body onload="getStudentStatus('q')">

<div class="w3-container w3-orange">
  <h1>Student Status</h1> 
  <h4>test bed</h4>
</div>
<br><br><br>

<div id="section">
<p>Result: <span id="StuStat"></span></p>
</div>

<div id="footer">
Copyright © xxxxxx.com
</div>



<div id="StuInfo">
<p>Cycle Info of:<span id="StuInfo"></span></p>
</div>


</body>
</html>

Any ideas ? 有任何想法吗 ? /koul / koul

try removing onload="getStudentStatus('q')" from the body tag, comment out var intShowResult = setInterval(function() {getStudentStatus("q") },60000); 尝试从body标签中删除onload="getStudentStatus('q')" ,注释掉var intShowResult = setInterval(function() {getStudentStatus("q") },60000); and try adding this instead to your javascript at the end. 并尝试将此添加到您的JavaScript最后。

The first call to getStudentStatus happens before the page has finished loading so if it does execute successfully there is no container element in the html to accept the response. 第一次调用getStudentStatus发生在页面加载完成之前,所以如果它确实成功执行,则html中没有容器元素可以接受响应。 Ensure the page content has fully loaded before calling the function. 在调用函数之前,请确保页面内容已完全加载。

function initialise(){
    call getStudentStatus(this,'q');
    setInterval( function() { getStudentStatus('q') }, 60000 );
}

document.addEventListener('DOMContentLoaded',initialise,false);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM