Ajax component Auto Discard and delay control download

Source: Internet
Author: User

<script>
/*
Copyright: The Great SB writer is a group of 27521907 of SB Pig
Above! The one who deletes is a pig!

Probably function, perform a group of trial downloads,
If multiple downloads are performed in the same group, the last request is executed.
and the request of different time to give up and delay control download.
*/
Window. XmlHttp = {}
Creating XML objects
Window. Xmlhttp.xmlobject = function () {
var haobject = null
if (Haobject = = null) try {var haobject = new XMLHttpRequest ();} catch (ERR) {}
if (Haobject = = null) try {var haobject = new ActiveXObject ("Microsoft.XMLHTTP");} catch (ERR) {}
if (Haobject = = null) try {var haobject = new ActiveXObject ("Msxml2.xmlhttp");} catch (ERR) {}
Return Haobject
}
Disconnect XMLHTTP TCP connections, some of the viewers or controls are invalid
Window. Xmlhttp.xmlclose = function (daobject) {
try {if (daobject!= null) Daobject.abort ();} catch (ERR) {}
try {if (daobject!= null) Daobject.close ();} catch (ERR) {}
}

Window. Xmlhttp.data = {}
Window. Xmlhttp.create = function (dadata) {
if (Xmlhttp.data[dadata.group]!= null) {
If this triggers a load of two identical groups within 50 milliseconds, then this load uses the current load and delays 100 milliseconds
if (Xmlhttp.data[dadata.group). Status = = 0 && xmlhttp.data[dadata.group]. Timer <= New Date (). GetTime ()) {
Xmlhttp.data[dadata.group]. Timer = new Date (). GetTime () + 100;
}
If the group is downloading data, but it is over 10 seconds, then the judge timed out and downloaded again
if (Xmlhttp.data[dadata.group). Status = = 1 && xmlhttp.data[dadata.group]. Timer < New Date (). GetTime ()-10000) {
Xmlhttp.data[dadata.group]. Loadbout = (Xmlhttp.data[dadata.group]. Loadbout | | 0) + 1
This group load timeout three times, then no longer continue
if (Xmlhttp.data[dadata.group). Loadbout < 3) {
Xmlhttp.data[dadata.group]. Status = 0
Xmlhttp.data[dadata.group]. Timer = new Date (). GetTime ();
}else{
Xmlhttp.xmlclose (Xmlhttp.data[dadata.group]. Object);
Delete Xmlhttp.data[dadata.group];
}
}
Downloading, accepting the command to change the address, recording the data, waiting for the current download to issue the command again
if (Xmlhttp.data[dadata.group). Status = = 1 && xmlhttp.data[dadata.group]. Timer <= New Date (). GetTime ()) {
Xmlhttp.data[dadata.group]. NewData = Dadata;
}
This group after the last load, in 1000 milliseconds, another load, then extended 500 milliseconds to reload, or extended 100 milliseconds to reload
if (Xmlhttp.data[dadata.group). Status = = 2) {
if (Xmlhttp.data[dadata.group). Timer < New Date (). GetTime ()-1000) {
Xmlhttp.data[dadata.group]. Status = 0
Xmlhttp.data[dadata.group]. Timer = new Date (). GetTime () + 100;
}else{
Xmlhttp.data[dadata.group]. Status = 0
Xmlhttp.data[dadata.group]. Timer = new Date (). GetTime () + 500;
}
}
}
Xmlhttp.data[dadata.group] = Xmlhttp.data[dadata.group] | | {
status:0,
Timer:new Date (). GetTime () + 100
};
Xmlhttp.data[dadata.group]. Data = Dadata

Xmlhttp.interval = Xmlhttp.interval | | Window.setinterval (
function () {
var IsNull = true;
for (Var Data in Xmlhttp.data) {
IsNull = false;
if (xmlhttp.data[data). Timer <= New Date (). GetTime ()) {
if (xmlhttp.data[data). Status = = 0) {
Xmlhttp.xmlclose (Xmlhttp.data[data]. Object);
try {
Xmlhttp.data[data]. Object = Xmlhttp.xmlobject ();
Xmlhttp.data[data]. Object.open ("Get", Xmlhttp.data[data]. data.address)
Xmlhttp.data[data]. Object.send ("")
Xmlhttp.data[data]. Status = 1

document.getElementById ("Dada"). InnerHTML = parseint (document.getElementById ("Dada"). InnerHTML) + 1
} catch (ERR) {
Xmlhttp.data[data]. Status = 3
}
}
if (xmlhttp.data[data). Status = = 1) {
if (xmlhttp.data[data). Object.readystate = = 4) {
var hastatus = Xmlhttp.data[data]. Object.status
if (hastatus = 200 | | Hastatus = = 0) {
Xmlhttp.data[data]. Content = Xmlhttp.data[data]. Object.responsetext
try {Xmlhttp.data[data]. Data.onload (Xmlhttp.data[data]); } catch (ERR) {
Xmlhttp.data[data]. Status = 3
}
}
Xmlhttp.xmlclose (Xmlhttp.data[data]. Object);
Xmlhttp.data[data]. Object = null;
Xmlhttp.data[data]. Status = 2
if (xmlhttp.data[data). NewData!= null) {
Xmlhttp.create (Xmlhttp.data[data]. NewData);
Delete Xmlhttp.data[data]. NewData;
}
}
}
}
After loading, if no new load occurs within 2000 Hao seconds, clear the variable
if (Xmlhttp.data[data]!= null && xmlhttp.data[data]. Status = = 2 && xmlhttp.data[data]. Timer < New Date (). GetTime ()-2000) {
Xmlhttp.xmlclose (Xmlhttp.data[data]. Object);
Delete Xmlhttp.data[data];
}
Error occurred, wait three seconds to clear variable
if (Xmlhttp.data[data]!= null && xmlhttp.data[data]. Status = = 3 && xmlhttp.data[data]. Timer < New Date (). GetTime ()-3000) {
Xmlhttp.xmlclose (Xmlhttp.data[data]. Object);
Delete Xmlhttp.data[data];
}
}
If no one has been loaded to continue, delete the thread.
if (IsNull = = True) {
Window.cleartimeout (Xmlhttp.interval)
Delete Xmlhttp.interval;
}
}
, 50)
}


function ABC (dathis) {
document.getElementById ("Ttt1"). InnerHTML = Dathis.value
Xmlhttp.create (
{
Group: "ABC",//Groups
Address: "http://bbs./post.php?action=newthread&fid=1&previewpost=%D4%A4%C0%C0%CC%FB%D7%D3&subject= "+ dathis.value,//Address
Onload:function (Dadata) {//load complete execution
document.getElementById ("Div1"). InnerHTML = (DaData.Content.match (/(size= "value=") ([^ "]+) (" tabindex= "3")/i) | | {}) [2].replace (/(^size= "value=") ("tabindex=" 3 "$)/I," ")
}
}
)
}
function DET (dathis) {
document.getElementById ("Ttt2"). InnerHTML = Dathis.value
Xmlhttp.create (
{
Group: "DET",//Groups
Address: "http://bbs./post.php?action=newthread&fid=1&previewpost=%D4%A4%C0%C0%CC%FB%D7%D3&subject= "+ dathis.value,//Address
Onload:function (Dadata) {//load complete execution
document.getElementById ("Div2"). InnerHTML = (DaData.Content.match (/(size= "value=") ([^ "]+) (" tabindex= "3")/i) | | {}) [2].replace (/(^size= "value=") ("tabindex=" 3 "$)/I," ")
}
}
)
}

</script>

<div>xmlhttp Open Number:<font id= "Dada" >0</font></div><br>


<div id= "ttt1" style= "width:100%; border: #999999 1px solid; padding:0px; margin:0px; font-size:12px; " >a</div>
<div id= "Div1" style= "width:100%; border: #999999 1px solid; padding:0px; margin:0px; font-size:12px; " >a</div>
<input style= "width:100%; border: #999999 1px solid; padding:0px; margin:0px; Font-size:12px;background: #D8E2F5 "value=" a "onkeypress=" ABC (This) "onkeyup=" ABC (This) "onchange=" abc ">

<div id= "ttt2" style= width:100%; border: #999999 1px solid; padding:0px; margin:0px; font-size:12px; " >a</div>
<div id= "Div2 style=" width:100%; border: #999999 1px solid; padding:0px; margin:0px : 12px; " >a</div>
<input style= "width:100% border: #999999 1px solid; padding:0px; margin:0px; font-size:12px; Background: #D8E2F5 "value=" "a" onkeypress= "DET (This)" onkeyup= "DET (This)" Onchange= "DET (This)"

Related Article

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.