52,797
社区成员
发帖
与我相关
我的任务
分享
<script type="text/javascript">
var xmlhttp;
function displayImage() {
var str
if (window.XMLHttpRequest) {
//针对FireFox,Mozillar,Opera,Safari,IE7,IE8
xmlhttp = new XMLHttpRequest();
//针对某些特定版本的mozillar浏览器的BUG进行修正
if (xmlhttp.overrideMimeType) {
xmlhttp.overrideMimeType("text/xml");
}
} else if (window.ActiveXObject) {
var activexName = ["MSXML2.XMLHTTP.6.0","MSXML2.XMLHTTP.5.0","MSXML2.XMLHTTP.4.0","MSXML2.XMLHTTP.3.0","MSXML2.XMLHTTP","Microsoft.XMLHTTP"];
for (var i = 0; i < activexName.length; i++) {
try{
xmlhttp = new ActiveXObject(activexName[i]);
break;
} catch(e){
}
}
}
if (!xmlhttp) {
alert("XMLHttpRequest对象创建失败!!");
return;
}
xmlhttp.onreadystatechange = callback;
xmlhttp.open("GET","matchwith.asp?str="+'&n='+Math.random(),true);
xmlhttp.send(null);
}
var i = 0;
var max_i = 10;
function callback()
{
if (xmlhttp.readyState == 4) {
//判断http的交互是否成功
if (xmlhttp.status == 200) {
//获取服务漆器端返回的数据
var divNode = document.getElementById("id6");
var img = div.getElementsByTagName("imghtml");
if (img.length == 0) {
img = document.createElement("imghtml");
while (div.childNodes.length > 0)
div.removeChild(div.childNodes[0]);
div.appendChild(img);
} else
img = img.item(0);
img.src = str;
if (i == max_i)
i = 0;
else
i ++;
divNode.innerHTML = responseText;
});
}
</script>
<body onload="displayImage()">
<input style="position:absolute; float:left; background:#0099FF; font-family:Arial, Helvetica, sans-serif; color:#CC3366; left: 610px; top: 120px;width:30px;" type="button" value="No" onclick="displayImage()">
<div id="id6"><img class="imghtml" src="" width="250" height="264" /></div>
<!--#include file="conn/conn.asp"-->
<%
dim Gender1,age1,age2,country,drrTmp
Gender1=request.Form("Gender")
age1=request.Form("age1")
age2=request.Form("age2")
country=request.Form("country")
set rs=server.createobject("adodb.recordset")
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"'and (age BETWEEN "&age1&" and "&age2&") and Country ='"&country&"'"
rs.open sql,conn,1,1
if rs.eof and rs.bof then
response.write("no one match with you want! please try again!")
else
for i=1 to rs.recordcount
if rs.eof then
exit for
end if
drrTmp=drrTmp&rs("Username")&","
session("eeee")=drrTmp
rs.movenext
next
end if
%>
<%
dim hrrTmp
hrrTmp=replace(session("eeee"),",","','")
set rs=server.createobject("adodb.recordset")
sql="select ID,USERNAME,PICPATH from ladlady where USERNAME in ('"&hrrTmp&"')"
rs.open sql,conn,1,3
if rs.eof and rs.bof then
response.Write("no photo!")
else
Do while not rs.eof
str=rs("PICPATH")
rs.movenext
loop
end if
rs.close
set rs = nothing
str=escape(str)
Response.Write str
set conn=nothing
%>
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"'and (age BETWEEN "&age1&" and "&age2&") and Country ='"&country&"'"
/*如果age1、age2是int类型的就不要“’”单引号,字符串就要了,所以sql语句有错误
看到这里,lz的ajax貌似没有提供age1、age2参数信息
age1=request.Form("age1")
判断下如果age1 == null 或 age1 == ""做些处理,下面一样*/
age2=request.Form("age2")
/*先不管lz是get还是post,参数至少也要有*/
xmlhttp.onreadystatechange = callback;
xmlhttp.open("GET","matchwith.asp?age1=22&age2=33&&n="+Math.random(),true);/*字符串拼接单引号、双引号不一致*/
/*动态参数,age1/age2为js变量值*/
xmlhttp.open("GET","matchwith.asp?age1="+ age1 +"&age2="+age2+"&&n="+Math.random(),true);
xmlhttp.send(null);
还有要注意ls几位提供的信息
//都没发送有动态页的键名称
xmlhttp.open("GET","matchwith.asp?str="+'&n='+Math.random(),true);
var divNode = document.getElementById("id6");
//div变量未申明,getElementsByTagName传递的标签名称也不对
//var img = div.getElementsByTagName("imghtml");
var img = divNote.getElementsByTagName("img");
if (img.length == 0) {
//imghtml。。。。没有这种标签
//img = document.createElement("imghtml");
img = document.createElement("img");
while (div.childNodes.length > 0)
divNote.removeChild(div.childNodes[0]); //======
divNote.appendChild(img); //=========
} else
img = img.item(0);
img.src = str;
if (i == max_i)
i = 0;
else
i ++;
//divNode.innerHTML = responseText; //你设innerHTML就覆盖掉img对象了