我正在使用「http://www.w3schools.com/Php/php_ajax_database.asp」來顯示下拉列表中onchange數據庫中的數據。我在數據庫中有大量的數據。所以加載需要時間。因此,我想在頁面中的某處顯示加載消息,直到數據顯示。如何在內容完全加載之前顯示加載消息
代碼:
<script>
function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
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("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","getuser.php?q="+str,true);
xmlhttp.send();
}
</script>
<form>
<select name="users" onChange="showUser(this.value)" style="margin-left: -680px;margin-top: -10px;">
<option value="1">Current Projects</option>
<option value="2">All Projects</option>
</select>
</form>
</div></div>
<div id="txtHint"> /*Content*/ </div>
getuser.php: 數據庫查詢,以顯示數據。