Code for automatic voting implemented using ajax

Source: Internet
Author: User

A friend entrusted me to vote for him:
Http://publish.sina.com.cn/04/13/413/search.php
The voting link is:
Http://publish.sina.com.cn/poll.php? P_id = 413 & t_id = 119
I made the following code and made it into a task manager. I opened it once every one minute and closed the window automatically. But the actual operation was ineffective and I don't know where the problem was? Copy codeThe Code is as follows: <Script language = "javascript">
Var CheckFreq = 1; // The queue check frequency. The default value is 1 second.
Var bRun = false; // prevents two programs from running at the same time
Function RunUrl (strUrl, strFreq)
{
This. url = strUrl; // The Running URL
This. freq = strFreq; // running frequency
This. lastrun = ''; // last running time
}
Var RunQueue = new Array ();
Function AddRun (strUrl, strFreq) // Add Run
{
If (strUrl = ''| strFreq ='') return
RunQueue [RunQueue. length] = new RunUrl (strUrl, strFreq)
}
Function Run (url) // Run the url
{
Var xmlHttp;
If (window. XMLHttpRequest) xmlHttp = new XMLHttpRequest ();
Else if (window. ActiveXObject) xmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
XmlHttp. onreadystatechange = function () {bRun = false ;}
XmlHttp. open ("GET", url, true );
XmlHttp. send (null );
BRun = true;
}
Function CheckRun () // check the queue
{
Var dtNow = new Date (), objRun;
Var tNow = dtNow. getTime ();
For (var I = 0; I <RunQueue. length; I ++)
{
ObjRun = RunQueue [I];
If (objRun. lastrun = '') objRun. lastrun = tNow;
If (! BRun & (objRun. freq = 0 | (tNow-objRun.lastrun)> objRun. freq * 1000 ))
{
ObjRun. lastrun = tNow;
Run (objRun. url );
}
}
}
AddRun ('HTTP: // publish.sina.com.cn/poll.php? P_id = 413 & t_id = 119 ', 10 );
SetInterval ('checkrun () ', CheckFreq * 1000); // setInterval
</Script>

<Script language = "javascript">
<! --
Function clock (){
I = I-1
Document. title = "After" + I + "minitues, this window will closed self! ";
If (I> 0) setTimeout ("clock ();", 20000 );
Else {window. opener = null; self. close ();}
}
Var I = 2
Clock ();
-->
</Script>

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.