底子薄,还请高手帮忙?

frankrenping 2010-09-08 03:42:07
调用后台数据库表中的图片(路径),打开页面时就任意显示一张图片在页面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
%>
...全文
97 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hoojo 2010-09-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ibm_hoojo 的回复:]

CSS code
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"'and (age BETWEEN "&age1&" and "&age2&") and Country ='"&country&"'"

/*如果age……
[/Quote]
html看js,6#
frankrenping 2010-09-08
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 ibm_hoojo 的回复:]
CSS code
sql="select Username,Gender,age,Country from customer1 where Gender='"&Gender1&"'and (age BETWEEN "&age1&" and "&age2&") and Country ='"&country&"'"

/*如果ag……
[/Quote]

前面的INT没有加“'”.

后面的确传参数是有问题。

可能HTML部分也有问题,不知能否指出?
frankrenping 2010-09-08
  • 打赏
  • 举报
回复
AJAX部分改成如下,还是不行,用FIREBUG显示DISPLAYIMAGE没有定义错误。

后台matchwith.asp以前也是这样写的用过没问题呀,现在出了错,为啥呢?

谢谢4楼的建议,用IDEA不习惯,感觉不好用,还不如DREAMWEAVER熟悉,可能时间短的原因,现在用FIREFOX中的FIREBUG还不错,也能发现不少错误。

<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("POST","matchwith.asp?",true);
//POST方式需要自己设置http的请求头
xmlhttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
//POST方式发送数据
xmlhttp.send("str="+'&n='+Math.random());
}
var i = 0;
var max_i = 10;
var divNode
function callback()
{
if (xmlhttp.readyState == 4) {
//判断http的交互是否成功
if (xmlhttp.status == 200) {
//获取服务漆器端返回的数据

var divNode = document.getElementById("id6");

var img = divNode.getElementsByTagName("img");
if (img.length == 0) {
img = document.createElement("img");
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>
hoojo 2010-09-08
  • 打赏
  • 举报
回复
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几位提供的信息


frankrenping 2010-09-08
  • 打赏
  • 举报
回复
显示错误如下:

在关键字 'and' 附近有语法错误。

/asp/matchwith.asp,行 10

正如你讲的那样,前台也可以改成POST,改了试下看看。
Go 旅城通票 2010-09-08
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 net_lover 的回复:]
你后台是
Gender1=request.Form("Gender")
age1=request.Form("age1")
age2=request.Form("age2")

POST方法获取数据,前面ajax是GET,是不行的
[/Quote]

看楼主的代码动态页肯定有问题,发送的值获取不到,sql语句有问题

//都没发送有动态页的键名称
xmlhttp.open("GET","matchwith.asp?str="+'&n='+Math.random(),true);



回调函数也一堆错误,楼主还是找一个好点的编辑器,有IDE提示的,如vs2008,这样输入变量名称就不那么容易出错了
 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对象了
孟子E章 2010-09-08
  • 打赏
  • 举报
回复
你先在浏览器里输入matchwith.asp看能否显示啊
孟子E章 2010-09-08
  • 打赏
  • 举报
回复
你后台是
Gender1=request.Form("Gender")
age1=request.Form("age1")
age2=request.Form("age2")

POST方法获取数据,前面ajax是GET,是不行的
孟子E章 2010-09-08
  • 打赏
  • 举报
回复
有什么问题?

52,797

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 Ajax
社区管理员
  • Ajax
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧