[英]show LOADING until page is completely loaded
I have this javascript: 我有这个javascript:
function createRequestObject(){
var req;
if(window.XMLHttpRequest){
//For Firefox, Safari, Opera
req = new XMLHttpRequest();
}
else if(window.ActiveXObject){
//For IE 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
//Error for an old browser
alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
}
//alert (req);
return req;
}
//Make the XMLHttpRequest Object
var http = createRequestObject();
function sendRequestTwo(method, url, head1){
head = head1
if(method == "get" || method == "GET"){
http.open(method,url);
http.onreadystatechange = handleResponseTwo;
http.send(null);
}
}
var head; //divs name
function handleResponseTwo(){
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
if(response){
document.getElementById(head).innerHTML = response;
}
}
}
This part 这部分
document.getElementById(head).innerHTML = response;
pastes the result back to my page. 将结果粘贴回我的页面。 How can I show "Loading" Before the page is completely loaded? 页面完全加载之前如何显示“正在加载”?
How about having a Div with your loading Html in the body like 像在体内那样加载Html的Div怎么样
<div id="loadingDiv" class="hiddenClass">Fancy rotating image goes here</div>
have a css class that says display:none; 有一个css类,上面显示display:none; then you could use this before 那么你可以在之前使用它
http.onreadystatechange = handleResponseTwo;
var myDiv = document.getElementById('loadingDiv');
myDiv.className = "showClass";
then after 然后
document.getElementById(head).innerHTML = response;
add 加
var myDiv = document.getElementById('loadingDiv');
myDiv.className = "hiddenClass";
All together 全部一起
function createRequestObject(){
var req;
if(window.XMLHttpRequest){
//For Firefox, Safari, Opera
req = new XMLHttpRequest();
}
else if(window.ActiveXObject){
//For IE 5+
req = new ActiveXObject("Microsoft.XMLHTTP");
}
else{
//Error for an old browser
alert('Your browser is not IE 5 or higher, or Firefox or Safari or Opera');
}
//alert (req);
return req;
}
//Make the XMLHttpRequest Object
var http = createRequestObject();
function sendRequestTwo(method, url, head1){
head = head1
if(method == "get" || method == "GET"){
var myDiv = document.getElementById('loadingDiv');
myDiv.className = "showClass";
http.open(method,url);
http.onreadystatechange = handleResponseTwo;
http.send(null);
}
}
var head; //divs name
function handleResponseTwo(){
if(http.readyState == 4 && http.status == 200){
var response = http.responseText;
if(response){
document.getElementById(head).innerHTML = response;
var myDiv = document.getElementById('loadingDiv');
myDiv.className = "hiddenClass";
}
}
}
I don't know the details of your HTML, but couldn't you just put loading in the tag that has an id="head"
? 我不知道您HTML的详细信息,但是您是否不能仅将加载内容放入具有id="head"
的标记中?
Then when you update the innerHTML, the loading would automatically be replaced. 然后,当您更新innerHTML时,将自动替换加载。 If you have more requirements, please describe. 如果您有更多要求,请描述。
您可以在sendRequestTwo
时将Loading打印到Head div中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.