Script binding callback enhanced version: standby url can fail and retry

Source: Internet
Author: User

In the past two years, with the increase of overseas users and the complexity of user conditions, our service deployment has also begun to become more complicated. Some users fail to access the domain name A, and the access to the domain name B may be smooth, other users are the opposite. In many cases, this is not a scheduling like gslb that can be detected and quickly adjusted in a timely manner. I cannot help but think about it. Can I retry failure? In fact, it was easy to change the code four years ago and make a theoretical experiment:

<HTML>
<HEAD>
<Script language = "JavaScript">
Var isIE = !! Window. ActiveXObject;
Var useFragment = false;
Function loadjs (url, callback, errcallback, url2, url3 ){
If (isIE ){
If (useFragment ){
Var df = document. createDocumentFragment ();
Df. visitCountCallBack = function (data ){
S. onreadystatechange = null;
Df = null;
Callback (data );
}
Var s = df. createElement ("SCRIPT ");
Df. appendChild (s );
S. onreadystatechange = function (ec, cb, u2, u3 ){
Return function (){
If (s. readyState = "loaded "){
S. onreadystatechange = null;
Df = null;
If (! U2 ){
Ec ();
} Else {
Loadjs (u2, cb, ec, u3)
}
}
}
} (Errcallback, callback, url2, url3)
S. src = url;
} Else {
Var I = new ActiveXObject ("htmlfile ");
I. open ();
I. parentWindow. visitCountCallBack = function (I ){
Return function (d ){
I. parentWindow. errcallback = null;
I = null;
Callback (d );
}
} (I );
I. parentWindow. errcallback = function (ec, cb, u2, u3 ){
Return function (){
I. parentWindow. errcallback = null;
I = null;
If (! U2 ){
Ec ();
} Else {
Loadjs (u2, cb, ec, u3)
}
}
} (Errcallback, callback, url2, url3)
I. write ("<script src = \" "+ url +" \ "> <\/script> <script defer> setTimeout (\" errcallback () \ ", 0) <\/script> ")
If (I) I. close (); // if the data is cached, the callback may be completed and the window is closed when this row is run.
}
} Else {
Var I = document. createElement ("IFRAME ");
I. style. display = "none ";
I. callback = function (o ){
Callback (o );
I. contentWindow. callback = null;
I. src = "about: blank"
I. parentNode. removeChild (I );
I = null;
};
I. errcallback = function (ec, cb, u2, u3 ){
Return function (){
If (! U2 ){
Ec ();
} Else {
Loadjs (u2, cb, ec, u3)
}
}
} (Errcallback, callback, url2, url3 );
I. src = "javascript: \" <script> function visitCountCallBack (data) {frameElement. callback (data) };< \/script> <script src = '"+ url +"'> <\/script> <script> setTimeout ('frameelement. errcallback () ', 0) <\/script> \"";
Document. body. appendChild (I );
}
}

Function init (){
Var spans = document. getElementsByTagName ("span ");
For (var I = 0; I <spans. length; I ++ ){
Var id = spans [I]. id;
Var url = "http://g.qzone.qq.com/fcg-bin/cgi_emotion_list.fcg? Uin = a "+ id; // retry caused by intentional manufacturing error
Var url2 = "http://g.qzone.qq.com/fcg-bin/cgi_emotion_list.fcg? Uin = B "+ id; // retry due to intentional re-manufacturing error
Var url3 = "http://g.qzone.qq.com/fcg-bin/cgi_emotion_list.fcg? Uin = "+ id;
Var callback = function (id) {return function (data ){
Document. getElementById (id). innerHTML = data. visitcount;
}
} (Id );
Var errcallback = function (id) {return function (){
Document. getElementById (id). innerHTML = "unable to connect to server ";
}
} (Id );
Loadjs (url, callback, errcallback, url2, url3 );
}
}
</SCRIPT>
</HEAD>
<BODY onload = "init ()">
12345 (invalid account) Traffic: <span id = "12345"> </span> <BR>
123456 of traffic: <span id = "123456"> </span> <BR>
20050606 of traffic: <span id = "20050606"> </span> <BR>
</BODY>
</HTML>
An error was intentionally made in the first two requests and it was successful only when the third url was attempted.

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.