日期:2014-05-16  浏览次数:20626 次

简单的不能再简单的AJAX原型调了1天了,还是只执行一次回调,请帮忙解决! - Web 开发 / Ajax
test.asp
<script>
var xmlHttpWL = false;
try {
  xmlHttpWL = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
  xmlHttpWL = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
  xmlHttpWL = false;
  }
}
if (!xmlHttpWL && typeof XMLHttpRequest != 'undefined') {
  xmlHttpWL = new XMLHttpRequest();
}
var xmlHttpWL01 = false;
try {
  xmlHttpWL01 = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
  try {
  xmlHttpWL01 = new ActiveXObject("Microsoft.XMLHTTP");
  } catch (e2) {
  xmlHttpWL01 = false;
  }
}
if (xmlHttpWL01 && typeof XMLHttpRequest != 'undefined') {
  xmlHttpWL01 = new XMLHttpRequest();
}


function add()
{
url = "Test_duibi.asp?action=setstr&pname="+document.getElementsByName("pname")[0].value;
xmlHttpWL.open("GET", url, true);
xmlHttpWL.send(null); 
}
function get()
{
url = "Test_duibi.asp";
xmlHttpWL01.onreadystatechange = setTable;
xmlHttpWL01.open("GET", url+"?t="+Math.random(), true);
xmlHttpWL01.send(null); 
}

function setTable()
{

  if (xmlHttpWL01.readyState == 4)
  {
if (xmlHttpWL01.status == 200)
{
var ss = xmlHttpWL01.responseText;
alert(ss);
}
  }
}
</script>
<INPUT TYPE="text" NAME="pname" > <INPUT TYPE="button" value="set" onclick="add();"> <INPUT TYPE="button" value="get" onclick="get();">
<%
response.write("Cookies="&Request.Cookies("WL_DuiBi"))
%>
================================
Test_duibi.asp
====================
<%@ LANGUAGE = VBScript codepage=65001%>
<%
response.charset="utf-8"
Response.Buffer = True 
response.expires=0 
Response.CacheControl="no-cache "  
Response.AddHeader "Pragma","no-cache"  

Select Case request("action")
Case "setstr" : setstr()
Case Else
getstr()
End Select 
Sub setstr()
response.cookies("WL_DuiBi")=Trim(request("pname"))
End Sub 

Sub getstr()
response.write(Request.Cookies("WL_DuiBi"))
End Sub 
%>

=======================
所有功能实现都没有问题,就是只回调一次,即使不用COOKICES,换成返回随机数或数据库内容也只回调一次,
还试过一个 xmlHttpWL01.abort(); 的也不行, 缓存也清了,url也加了随即参数,但还是不行,请教?

------解决方案--------------------
参见
http://topic.csdn.net/u/20080118/10/4a61975c-cfe1-4fa1-912d-7bcf61186b71.html