- Fotas.net. Call = function (Uri, predefine, callback, Param, timeout, retry)
- {
- VaR uniqid = fotas. uniqid ();
- Fotas. Callbacks [uniqid] = function (){
- Delete fotas. Callbacks [uniqid];
- Document. Body. removechild (fotas. scripts [uniqid]);
- Delete fotas. scripts [uniqid];
- Ajax = new object ();
- Ajax. readystate = 4;
- Ajax. Status = 200;
- Ajax. responsetext =;
- If (callback! = Undefined)
- Callback (Ajax );
- };
- If (URI. indexof ('? ')! =-1)
- Uri + = "& jsonp =" + encodeuricomponent ("fotas. Callbacks [" + uniqid + "]") + "& Key =" + fotas. Key;
- Else
- Uri + = "? Jsonp = "+ encodeuricomponent (" fotas. Callbacks ["+ uniqid +"] ") +" & Key = "+ fotas. Key;
- If (Param! = Undefined)
- Uri + = "&" + Param;
- Fotas. scripts [uniqid] = Document. createelement ('script ');
- Fotas. scripts [uniqid]. setattribute ("type", "text/JavaScript ");
- Fotas. scripts [uniqid]. src = fotas. Uri + URI;
- Document. Body. appendchild (fotas. scripts [uniqid]);
- }
- Fotas.net. Call = function (Uri, predefine, callback, Param, timeout, retry)
- {
- VaR Ajax = createxmlhttprequest ();
- Ajax. onreadystatechange = function () {callback (Ajax );};
- If (Param! = Undefined)
- {
- Ajax. Open ("Post", Uri, true );
- Ajax. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded ");
- Ajax. setRequestHeader ("connection", "close ");
- If (predefine! = Undefined)
- Ajax = predefine (Ajax );
- Ajax. Send (PARAM );
- } Else {
- Ajax. Open ("get", Uri, true );
- If (predefine! = Undefined)
- Ajax = predefine (Ajax );
- If (window. XMLHttpRequest)
- Ajax. Send (null );
- Else if (window. activexobject)
- Ajax. Send ();
- }
- If (timeout! = Undefined)
- {
- VaR trynow = 0;
- If (retry = undefined)
- Retry = 0;
- Function connectioncheck ()
- {
- If (Ajax. readystate! = 4)
- {
- Ajax. Close ();
- Trynow ++;
- If (trynow <= retry)
- {
- If (Param! = Undefined)
- {
- Ajax. Open ("Post", Uri, true );
- Ajax. Send (PARAM );
- } Else {
- Ajax. Open ("get", Uri, true );
- If (window. XMLHttpRequest)
- Ajax. Send (null );
- Else if (window. activexobject)
- Ajax. Send ();
- }
- SetTimeout (connectioncheck, timeout );
- }
- }
- }
- SetTimeout (connectioncheck, timeout );
- }
- }
The two fotas.net. Calls are compatible with each other. The first is used for cross-origin Ajax (jsonp), and the second is the standard XMLHttpRequest. Therefore, the second option supports setting timeout and request header.