底子薄,还请高手帮忙?

frankrenping frankrenping 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
调用后台数据库表中的图片(路径),打开页面时就任意显示一张图片在页面DIV ID=ID6中,点击按钮“NO" 就换另外一张图片,再点又换一张,按其他方法做了一个,页面显示有问题,请帮忙改正,谢谢。

AJAX:
<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>

HTML部分:

<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>



后台:
matchwith.asp

<!--#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
%>
...全文
评论 9
收藏 已收藏
分享
返回顶部
frankrenping
Ajax 52,778 成员 25,334 内容