Ajax No Refresh

Source: Internet
Author: User

var xmlhttp=false;//creates a Boolean variable to detect if it is a legitimate instance of IE
try{//Detect if you are using IE
Xmlhttp=new actionxobject (' msxml2.xmlhttp ');//If JS version is greater than 5
}catch (e) {//If not, use the old version of the ActionX object
try{
Xmlhttp=new actionxobject ("microslft.xmlhttp");//If you are using IE browser
}catch (E2) {}
}
If you are using a non-IE browser, create a JS instance of the object
if (!xmlhttp && typeof xmlhttprequest!= "undefined") {
try{
Xmlhttp=new XMLHttpRequest ();
}catch (E3) {
Xmlhttp=false;
}
}

Timer=window.setinterval ("ShowTime ()", 1000);//Call ShowTime function once every second
Define the Showtime function to read data from a showtime.php file through a XMLHttpRequest object
function ShowTime () {
Xmlhttp.open ("Post", "showtime.php", true);//Send a new request with the Post method
Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate==4) {//If the server responds to a request, do the following
Tet=xmlhttp.responsetext; Gets the response information returned
Gets the information given to the DIV tag
document.getElementById ("Show_time"). Innerhtml=tet;
}
}
Xmlhttp.send (NULL); Send Request
}


Timer=window.setinterval ("Sparetime ()", 1000);//Call sparetime function once every second
Define the Sparetime function to read data from a sparetime.php file through a XMLHttpRequest object
function Sparetime () {
Xmlhttp.open ("Post", "sparetime.php", true);//Send a new request with the Post method
Xmlhttp.onreadystatechange=function () {
if (xmlhttp.readystate==4) {//If the server responds to a request, do the following
Tet=xmlhttp.responsetext; Gets the response information returned
Gets the information given to the DIV tag
document.getElementById ("Sparetime"). innerhtml=tet;//when the remaining time is 00:00
if (tet== "00:00") {//Submit data in Form1 form
Form1.submit ();
}
}
}
Xmlhttp.send (NULL); Send Request
}

Ajax No Refresh

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.