积极答复者
关于一个Ajax的问题

问题
-
///////////////////shopcar.asp/////////////////////////////
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<div style="text-align:center">
<div>
<img src="images/002.jpg" alt="" id="imgOne" name="imgTwo"/>
<br />
<a href="#" onclick="sendGet('shopCarShow.asp','goodsName=K-0001','login_result');">加入购物车</a>
<div id="goodsDivOne"></div>
</div>
</div>
</body>
</html>
<script language="javascript" type="text/javascript">
var xmlHttp;
function createXMLHttpRequest()
{
//兼容服务器
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");//非IE
}
else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
return xmlHttp;
}
xmlHttp=createXMLHttpRequest();
function sendGet(url,par,callback)
{
url=url+"?"+par;
xmlHttp.open("GET",url,true);
xmlHttp.onreadystatechange=eval(callback);
xmlHttp.send(null);
}
function login_result()
{
if(xmlHttp.readyState==4)
{
value=xmlHttp.responseText;
if(xmlHttp.status==200)
{
if(value=="yes")
{
document.getElementById("goodsDivOne").innerHTML=("成功!<a href='shopCarShow.asp'>查看</a>");
}
else if(value=="no")
{
document.getElementById("goodsDivOne").innerHTML=("失败!");
}
else
{
document.getElementById("goodsDivOne").innerHTML=("失败and恶心!");
//alert(value);
}
}
else
{
document.getElementById("goodsDivOne").innerHTML("抱歉添加失败!");
}
}
}
</script>
/////shopcarshow.asp页面/////////
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head><body>
<%
'dim car
session("aa")=request("goodsName")
'car=Split(request("goodsName"),":")
'response.Write(car(0))
response.Write(session("aa"))
if request("goodaName")<>"" or request("goodaName")<>null then
response.Write("yes")
else
response.Write("no")
end if
response.End()
%>
</body>
</html>
问在shopCarshow.asp中的session("aa")的值是多少?为什么在shopcar.asp页面显示却是“失败and恶心”呢????高手讲讲,最好细点!- 已移动 Raymond TangModerator 2010年1月22日 7:40 (发件人:.NET Framework 一般性问题讨论区)
- 已编辑 我来学习 2010年1月22日 8:03
答案
-
response.Write(session("aa"))
if request("goodaName")<>"" or request("goodaName")<>null then
response.Write("yes")
else
response.Write("no")
end if
response.End()
你这段代码很明显有问题
你先都将Session中的aa输出了 那么页面返回的怎么可能是 yes或者no呢
'response.Write(session("aa"))
response.Clear()
if request("goodaName")<>"" or request("goodaName")<>null then
response.Write("yes")
else
response.Write("no")
end if
response.End()
Memory all alone in the moonlight~My Blog in .NET~~~- 已标记为答案 Andrew_ZhuModerator 2010年1月27日 9:53
全部回复
-
value=xmlHttp.responseText;
if(xmlHttp.status==200)
换成
if(xmlHttp.status==200)
{
value=xmlHttp.responseText;
}
你采用的Post方法却没有send anything 当然 request("goodsName")就是空的了
xmlHttp.send("goodsName=yes");
Memory all alone in the moonlight~My Blog in .NET~~~ -
response.Write(session("aa"))
if request("goodaName")<>"" or request("goodaName")<>null then
response.Write("yes")
else
response.Write("no")
end if
response.End()
你这段代码很明显有问题
你先都将Session中的aa输出了 那么页面返回的怎么可能是 yes或者no呢
'response.Write(session("aa"))
response.Clear()
if request("goodaName")<>"" or request("goodaName")<>null then
response.Write("yes")
else
response.Write("no")
end if
response.End()
Memory all alone in the moonlight~My Blog in .NET~~~- 已标记为答案 Andrew_ZhuModerator 2010年1月27日 9:53