服务器端用VBscript,客户端请求老是说什么语句未结束........

andyjean 2008-04-08 07:40:51
这是我的一个服务器端程序:getPrices.asp:
==========================
<%
Dim conn,rs1
Dim connStr
Dim sqlStr1,sqlStr2,sqlStr3,gameID,serverID
'创建数据库连接对象并打开
Set conn=server.createobject("adodb.connection")
Set rs = server.CreateObject("ADODB.Recordset")
connStr="Provider=Microsoft.jet.oledb.4.0;data Source="& server.mappath("data.mdb")
conn.open(connStr)
gameID=Request.QueryString("gameID")
serverID= Request.QueryString("serverID")
sqlStr1="select priceSource,priceContent,updateTime,orderURL from Servers where Servers.gameID='"& gameID &"'"
sqlStr2=sqlStr1&" and Servers.serverID='"& serverID &"'"
sqlStr3="select coinType from Games where Games.gameID='"& gameID &"'"
rs.Open sqlStr3,conn
Response.Write " <table> <tr>"
Response.Write " <td>WEBsite </td>"
Dim coinTypeStr
while not rs.eof
coinTypeStr=rs("coinType")
rs.movenext
wend
Dim arrayCoinType=Split(coinTypeStr,",",-1,1)
for i=0 to ubound(arrayCoinType)-2
Response.Write " <td>"& arrayCoinType(i) &" </td>"
next
rs.close
Response.Write " <td>Update </td> <td>Order </td> </tr>"
rs.Open sqlStr2,conn
while not rs2.eof
Response.Write " <tr>"
Response.Write " <td>"& rs("priceSource") & " </td>"
Dim priceStr=rs("priceContent")
Dim myArray=Split(priceStr, ",", -1, 1)
for i=0 to ubound(myArray)-2
Response.Write(" <td>"& myArray(i) &" </td>")
next
Response.Write " <td>" & rs("updateTime") &" </td>"
Response.Write " <td> <img src='order.gif'> <a href='"& rs("orderURL") &" </a> </img> </td>"
Response.Write " </tr>"
rs.movenext
wend
Response.Write " </table>"
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
============================

可客户端请求时,却出现这样的错误:

错误类型:
Microsoft VBScript 编译器错误 (0x800A0401)
语句未结束
/coinPrice/getPrice.asp, line 23, column 17
Dim arrayCoinType=Split(coinTypeStr,",",-1,1)
----------------^

是不是Split的用法不对呢??

coinTypeStr=rs("coinType") 这句中:表记录中coinType字段(文本型的)的值是这样的,比如A1,A2,A3,A4
然后我就想用split方法拆分成一个数组,但老是说什么语句未结束...........请问我哪里不对啊?
...全文
133 点赞 收藏 26
写回复
26 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
beyondamane 2008-04-08
xmlhttp1.open("get","getPrice.asp?serverID="+serverID+"&"+gameID,false);
gameID没有赋值
回复
beyondamane 2008-04-08
我眼拙,实在看不出问题在哪,getPrice.asp没有问题
test.asp也看不出什么问题
回复
beyondamane 2008-04-08
不好意思,楼上弄错了
回复
beyondamane 2008-04-08
while not rs.eof
Response.Write " <tr>"
两行应该换一下位置
回复
beyondamane 2008-04-08
javascript加入alert()
是不能分辨html标签的,他只能把html标签作为字符串打印出来
javascript命令和html是不一样的
比如换行

javascript的alert(),换行命令是: \n
html是<br>
回复
andyjean 2008-04-08
是这样的
getPrice.asp的全部代码:
=================================
<%
Dim conn,rs
Dim connStr
Dim sqlStr1,sqlStr2,sqlStr3,gameID,serverID
'创建数据库连接对象并打开
Set conn=server.createobject("adodb.connection")
Set rs = server.CreateObject("ADODB.Recordset")
connStr="Provider=Microsoft.jet.oledb.4.0;data Source="& server.mappath("data.mdb")
conn.open(connStr)
gameID=Request.QueryString("gameID")
serverID= Request.QueryString("serverID")
sqlStr1="select priceSource,priceContent,updateTime,orderURL from Servers where Servers.gameID='"& gameID &"'"
sqlStr2=sqlStr1&" and Servers.serverID='"& serverID &"'"
sqlStr3="select coinType from Games where Games.gameID='"& gameID &"'"
rs.Open sqlStr3,conn
Response.Write "<table><tr>"
Response.Write "<td>WEBsite</td>"
Dim coinTypeStr
while not rs.eof
coinTypeStr=rs("coinType")
rs.movenext
wend
Dim arrayCoinType
arrayCoinType=Split(coinTypeStr,",",-1,1)
for i=0 to ubound(arrayCoinType)
Response.Write "<td>"& arrayCoinType(i) &"</td>"
next
rs.close
Response.Write "<td>Update</td><td>Order</td></tr>"
rs.Open sqlStr2,conn
while not rs.eof
Response.Write "<tr>"
Response.Write "<td>"& rs("priceSource") & "</td>"
Dim priceStr
priceStr=rs("priceContent")
Dim myArray
myArray=Split(priceStr, ",", -1, 1)
for i=0 to ubound(myArray)
Response.Write("<td>"& myArray(i) &"</td>")
next
Response.Write "<td>" & rs("updateTime") &"</td>"
Response.Write "<td><a href='"& rs("orderURL") &"'><img src='order.gif'></img>"&"</a></td>"
Response.Write "</tr>"
rs.movenext
wend
Response.Write "</table>"
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
==========================
奇怪的是:
如果我在浏览器地址拦输入比如:http://localhost/coinPrice/getPrice.asp?serverID=s3&gameID=A4
就会有结果.
结果如下:
=====WEBsite 100G 1000G 10000G Update Order
www.barca.cn 24.4 229.5 2012 0404 *****

但是假如我在test.asp页面选第二个下拉列表框后得到的结果却是:

=====WEBsite 100G 1000G 10000G Update Order
就是看不到值,而且 我在test.asp端的javascript加入alert()弹出框方法测试返回的数据都是
<table><tr><td>WEBsite</td><td>100G</td>1000G<td>10000G</td><td>Update</td><td>Order</td></tr></table>

请问这是什么原因呢??谢谢!!!

回复
feng03_12 2008-04-08
while not rs.eof
coinTypeStr=rs("coinType")
rs.movenext
wend
Dim arrayCoinType
arrayCoinType=Split(coinTypeStr,",",-1,1)
for i=0 to ubound(arrayCoinType)
Response.Write " <td>"& arrayCoinType(i) &" </td>"
next
这块儿
在while循环中coinTypeStr=rs("coinType")会不会最后在cointypestr变量中只会得到最后一条记录的内容?
回复
beyondamane 2008-04-08
请求getPrice.asp,你得把这个代码给贴出来部分吧,问题出在哪,你得自己先做一下判断呀
回复
andyjean 2008-04-08
哦,这就是客户端的一个调用函数
==============
function getPrices(){
var gameID=document.forms.form1.game_select.value;
var serverID=document.forms.form1.server_select.value;
var showbody=document.getElementById("showbody");
var loading=document.getElementById("loading");
var coinType=document.getElementById("coinType");
var price=document.getElementById("price");
if(document.forms.form1.server_select.selectedIndex==0){
showbody.style.display="none";
}else{
loading.style.display="block";
var xmlhttp1;
try{
xmlhttp1=new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp1=new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp1=new XMLHttpRequest();
}catch(e){}
}
}
xmlhttp1.onreadyStateChange=function(){
if(xmlhttp1.readyState==4){
if(xmlhttp1.status==200){
loading.style.display="none";
price.style.display="block";
showbody.style.display="block";
coinType.style.display="block";
price.innerHTML=xmlhttp1.responseText;
}else{
alert("Some Errors on Network!");
}
}
}
xmlhttp1.open("get","getPrice.asp?serverID="+serverID+"&"+gameID,false);
xmlhttp1.send(null);
}
}
回复
beyondamane 2008-04-08
因为你贴的代码太长了,把关键代码贴出来就可以了
回复
andyjean 2008-04-08
怎么没人理了呢?
调式出现新问题了,所以还没有结帖 给分
大家就.....????
回复
andyjean 2008-04-08
啊,现在更奇怪,
根本读不到任何数据了

===============客户端test.asp====
这是其中一段:
<%@ Language = "VBScript" %>
<%
Dim conn,rs
Dim connStr
Dim sqlStr
Set conn=Server.CreateObject("ADODB.Connection")
Set rs = Server.CreateObject("ADODB.Recordset")
connStr="Provider=Microsoft.jet.oledb.4.0;data Source="& server.mappath("data.mdb")
conn.open connStr
sqlStr="select gameID,gameName,coinType from Games"
rs.Open sqlStr,conn'you'd better not use this ---rs=conn.execute(sqlStr)
%>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Ajax for Data-Reading </title>
<link rel="stylesheet" href="style.css" type="text/css" media="all">
</head>
<body>
<form name="form1">
<div id="game_div">
<select name="game_select" onChange="getServers()">
<option value="0">Choose one game</option>
<% do while not rs.eof
Response.write("<option value='" & rs("gameID") & "'>")
Response.write(rs("gameName"))
Response.write("</option>")
rs.movenext
loop
rs.close
conn.close
set rs=nothing
set conn=nothing
%>
</select>
</div>
<div id="server_div"></div>
<div id="showbody">
<div id="loading"></div>
<div id="coinType"></div>
<div id="price"></div>
</div>
</form>
</body>
</html>
<script language="JavaScript"type="text/javascript">

var showbody=document.getElementById("showbody");
var loading=document.getElementById("loading");
var coinType=document.getElementById("coinType");
var price=document.getElementById("price");

function getServers(){
var gameID=document.forms.form1.game_select.value;
var showbody=document.getElementById("showbody");
var loading=document.getElementById("loading");
var coinType=document.getElementById("coinType");
var price=document.getElementById("price");
if(document.forms.form1.game_select.selectedIndex==0){
document.forms.form1.server_select.length=0;
server_div.style.display="none";
showbody.style.display="none";
return;
}else{
var xmlhttp;
try{
xmlhttp=new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp=new XMLHttpRequest();
}catch(e){}
}
}
xmlhttp.onreadystatechange=function(){
if(xmlhttp.readyState==4){
if(xmlhttp.status==200){
var server_div=document.getElementById("server_div");
server_div.style.display="block";
showbody.style.display="none";
server_div.innerHTML=xmlhttp.responseText;
}else{
alert("Some Errors on Network!");
}

}
}
xmlhttp.open("get","getServers.asp?gameID="+gameID,false);
xmlhttp.send(null);
}

}
function getPrices(){
var gameID=document.forms.form1.game_select.value;
var serverID=document.forms.form1.server_select.value;
var showbody=document.getElementById("showbody");
var loading=document.getElementById("loading");
var coinType=document.getElementById("coinType");
var price=document.getElementById("price");
if(document.forms.form1.server_select.selectedIndex==0){
showbody.style.display="none";
}else{
loading.style.display="block";
var xmlhttp1;
try{
xmlhttp1=new ActiveXObject('Msxml2.XMLHTTP');
}catch(e){
try{
xmlhttp1=new ActiveXObject('Microsoft.XMLHTTP');
}catch(e){
try{
xmlhttp1=new XMLHttpRequest();
}catch(e){}
}
}
xmlhttp1.onreadyStateChange=function(){
if(xmlhttp1.readyState==4){
if(xmlhttp1.status==200){
loading.style.display="none";
price.style.display="block";
showbody.style.display="block";
coinType.style.display="block";
alert(xmlhttp1.responseText);
price.innerHTML=xmlhttp1.responseText;
}else{
alert("Some Errors on Network!");
}
}
}
xmlhttp1.open("get","getPrice.asp?serverID="+serverID+"&"+gameID,false);
xmlhttp1.send(null);
}
}
</script>

===========================
结果却是:
WEBsite Update Order

===============
无论你怎么改变选值,数据库中应该是有数据的!!!为什么呢
回复
andyjean 2008-04-08
哦,是这样啊
呵呵 ,12楼 你也是messi的fans哦??
幸会!!!!!
回复
snlixing 2008-04-08
for i=0 to ubound(arrayCoinType)
回复
beyondamane 2008-04-08
for i=0 to ubound(arrayCoinType)-2
你一共3个值,在循环的时候被你去掉2个,当然是只剩1个了
回复
beyondamane 2008-04-08
sqlStr3="select coinType from Games where Games.gameID='"& gameID &"'"
rs.Open sqlStr3,conn
Response.Write " <table> <tr>"
Response.Write " <td>WEBsite </td>"
Dim coinTypeStr
while not rs.eof
coinTypeStr=rs("coinType")
rs.movenext
wend
Dim arrayCoinType=Split(coinTypeStr,",",-1,1)
for i=0 to ubound(arrayCoinType)-2
Response.Write " <td>"& arrayCoinType(i) &" </td>"
next
回复
苍白之月 2008-04-08
[Quote=引用 4 楼 beyondamane 的回复:]
redim
[/Quote]

这个答案也很正确
回复
andyjean 2008-04-08
sqlStr3="select coinType from Games where Games.gameID='"& gameID &"'"
rs.Open sqlStr3,conn
Response.Write " <table> <tr>"
Response.Write " <td>WEBsite </td>"
Dim coinTypeStr
while not rs.eof
coinTypeStr=rs("coinType")
rs.movenext
wend
Dim arrayCoinType=Split(coinTypeStr,",",-1,1)
for i=0 to ubound(arrayCoinType)-2
Response.Write " <td>"& arrayCoinType(i) &" </td>"
next

本来rs("coinType") 读取出来的值应该是(比如):100G,1000G,10000G
可经过拆分 却只得到一个值!!!
===========
WEBsite 100G Update Order
www.barca.cn 24.4 0404 <a href='www.barca.cn
==================

回复
andyjean 2008-04-08
啊 郁闷又出现新的问题了
回复
andyjean 2008-04-08
哦,刚才我把你说的那两个地方改了,
Dim arrayCoinType
arrayCoinType=Split(coinTypeStr,",",-1,1)
Dim priceStr
priceStr=rs("priceContent")
Dim myArray
myArray=Split(priceStr, ",", -1, 1)

恩,可以了!!!!!!!!!!!!!!!!!!!!!
谢谢你哈 朋友!!!!给你全分!!!!!!!!!
回复
加载更多回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-04-08 07:40
社区公告
暂无公告