我正在使用以下脚本进行ajax调用:
window.onload = function() {
if (!session) {
layoutType = document.documentElement.clientWidth;
var xmlhttp;
if (window.XMLHttpRequest)
xmlhttp=new XMLHttpRequest();
}
else
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
window.location.reload();
}
}
xmlhttp.open("POST","core/session.php?bW=" + bW,true);
xmlhttp.send();
}
}
我想在pahe加载时插入加载图像和一些文本。我怎么做的?
我想插入以下图片链接和文字:
<img src="cdn/images/ajax-loader.gif" />
<h3>Please wait while we load</h3>
请帮忙。
答案 0 :(得分:1)
你可以在加载时添加图像,当ajax加载时它会基本上覆盖你的图像 ajax装载机
<script>
var DisplayIMge = document.getElementById("ajaxdiv");
DisplayIMge.innerHTML = "<img src='cdn/images/ajax-loader.gif' /><h3>Please wait while we load</h3>"
</script>
例如,这里是基于你正在使用的ajax
<html>
<head>
<script type="text/javascript">
function showHint(str)
{
if (str.length==0)
{
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("POST","core/session.php?bW=" + bW,,true);
xmlhttp.send();
}
</script>
</head>
<body>
<p><b>Start typing a name in the input field below:</b></p>
<form>
First name: <input type="text" onkeyup="showHint(this.value)" size="20" />
</form>
<p><div id="ajaxdiv"><div></p>
</body>
</html>