Alice's Blog

Alice's Blog
  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<script>
   
  // remote scripting library
  // (c) copyright 2005 modernmethod, inc
  var sajax_debug_mode = false;
  var sajax_request_type = "GET";
  var sajax_target_id = "alice";
  
  function sajax_debug(text) {
   if (sajax_debug_mode)
    alert("RSD: " + text)
  }
   function sajax_init_object() {
    sajax_debug("sajax_init_object() called..")
    
    var A;
   try {
    A=new ActiveXObject("Msxml2.XMLHTTP");
   } catch (e) {
    try {
     A=new ActiveXObject("Microsoft.XMLHTTP");
    } catch (oc) {
     A=null;
    }
   }
   if(!A && typeof XMLHttpRequest != "undefined")
    A = new XMLHttpRequest();
   if (!A)
    sajax_debug("Could not create connection object.");
   return A;
  }
  function sajax_do_call(func_name, args) {
   var i, x, n;
   var uri;
   var post_data;
   var target_id;
   
   sajax_debug("in sajax_do_call().." + sajax_request_type + "/" + sajax_target_id);
   target_id = sajax_target_id;
   if (sajax_request_type == "")
    sajax_request_type = "GET";
   
   uri = document.all.url.value;
   if (sajax_request_type == "GET") {
   
    if (uri.indexOf("?") == -1)
     uri += "?rs=" + escape(func_name);
    else
     uri += "&rs=" + escape(func_name);
    uri += "&rst=" + escape(sajax_target_id);
    uri += "&rsrnd=" + new Date().getTime();
    
    for (i = 0; i < args.length-1; i++)
     uri += "&alice" + (i + 1) + "=" + escape(args[i]);
    post_data = null;
    //alert(uri);
   }
   else if (sajax_request_type == "POST") {
    post_data = "rs=" + escape(func_name);
    post_data += "&rst=" + escape(sajax_target_id);
    post_data += "&rsrnd=" + new Date().getTime();
    
    for (i = 0; i < args.length-1; i++)
     post_data = post_data + "&rsargs[]=" + escape(args[i]);
   }
   else {
    alert("Illegal request type: " + sajax_request_type);
   }
   
   x = sajax_init_object();
   x.open(sajax_request_type, uri, true);
   
   if (sajax_request_type == "POST") {
    x.setRequestHeader("Method", "POST " + uri + " HTTP/1.1");
    x.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
   }
   
   x.onreadystatechange = function() {
    if (x.readyState != 4)
     return;

    sajax_debug("received " + x.responseText);
    
    var status;
    var data;
    //alert(x.responseText);
    status = x.responseText.charAt(0);
    //data = x.responseText.substring(2);
    data = x.responseText;
    if (status == "-")
     alert("Error: " + data);
    else {//alert(target_id);
     if (target_id != "")
     if(func_name!="change")
     {
     document.getElementById(target_id).value = data;
     }
     else
     {
     document.all.annier.innerHTML=data;
     }
     else
      args[args.length-1](eval(data));
    }
   }
   sajax_debug(func_name + " uri = " + uri + "/post = " + post_data);
   x.send(post_data);
   sajax_debug(func_name + " waiting..");
   delete x;
   return true;
  }
  
  
    
  // wrapper for add_line  
  function x_add_line() {
   sajax_do_call("add_line",
    x_add_line.arguments);
  }
  
    
  // wrapper for refresh  
  function x_refresh() {
   sajax_do_call("refresh",
    x_refresh.arguments);
  }
  
   
 var check_n = 0;
 var old_data = "--";
 
 function refresh_cb(new_data) { 
  if (new_data != old_data) {
   document.getElementById("wall").innerHTML = new_data;
   setTimeout("refresh()", 1000);
   old_data = new_data;
  } else {
   setTimeout("refresh()", 2500);
  }
  document.getElementById("status").innerHTML = "Checked #" + check_n++;
 }
 
 function refresh() {
  x_add_line("","","", add_cb);
 }
 
 function add_cb() {
  // we don't care..
 }

 function add() {
  var thename;
  var thetime;
  var thevalue;
  thename = document.all.thename.value;
  thetime = document.all.thetime.value;
  thevalue = document.all.thevalue.value;
  if (thename == "")
   return;
  sajax_request_type = "GET";
  x_add_line(thename,thetime,thevalue, add_cb);
  //document.all.thename.value = "";
 }
 function change()
 {
 //alert(document.all.keyword.value);
 kword=document.all.keyword.value;
 var ar = new Array(2);
 ar[0]="change";
 ar[1]=kword;
 ar[2]="xxx";
 sajax_do_call("change",
    ar);
 //document.all.annier.innerHTML=kword;
 }
 </script>
</HEAD>


<BODY>
要执行的网址:<input type='text' name="url" value="http://blog.tfol.com/vote/vote.aspx?id=17" size=80><br>
间隔多少秒执行一次:<input type='text' value="10" name="seconds"><br>
已经执行了多少次:<div id=times>0</div><div id=imgs><img width=0 height=0 name="vote" src=""></div>

<input type="hidden" onkeyup="change()" name="keyword"><input type="hidden" value="清除所有内容" onclick="x_add_line('deleteall','','', add_cb)"><span id="annier" name="annier"></span>
<SCRIPT LANGUAGE="JavaScript">
var i=0;
function kiss()
{
refresh();
//doIt(document.all.url.value);
//document.getElementById("imgs").innerHTML="<img width=10 height=10 name=\"vote\" src=\"" + document.all.url.value + "\"></iframe>";
//document.all.vote.src=document.all.url.value;
i++;
document.getElementById("times").innerText=i;
}
//setTimeout("kiss()",5000);
kiss();
setInterval("kiss()",(document.all.seconds.value)*1000);
</SCRIPT><BR>
<textarea id="alice" name="alice" rows=100 cols=60></textarea>
</BODY>
</HTML>