AJAX的传值问题 - Web 开发 / Ajax
<!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>
<title>Ajax - Sample1</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!--请一定要将此页的编码设为UTF-8,否则aixq将com出现乱码 else's blog-->
<meta http-equiv="pragma" content="no-cache"/>
<script language="javascript" type="text/javascript">
function GE(a){return document.getElementById(a);}
function Check(){
if(GE('username').value==''){GE('msg').innerHTML='用名不能为空';return false}
if(GE('password').value==''){GE('msg').innerHTML='password 不能为空';return false}
var X=new ActiveXObject("Msxml2.XMLHTTP");
if(X){
GE('regsubmit').disabled=true;
X.onreadystatechange=function(){
if(X.readyState==4){
if(X.status==200){
eval(X.responseText)
}
else{GE('msg').innerHTML=X.statusText}
}
else{GE('msg').innerHTML="正在提交数据..."}
};
X.open('POST','ajax.asp',true);
X.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
var SendData = 'username='+GE('username').value
X.send(SendData)
}
else{
GE('msg').innerHTML='你的浏览器不支持XMLHttpRequest'
}
}
</script>
<label>
<input type="text" name="username" id="username">
</label>
<label>
<input type="submit" name="Submit" value="提交" onClick="check();" id="regsubmit">
</label>
</body>
</html>
<%
session("yhm")=request("username")
response.write(request("username"))
%>
我想要获得文本框里的用户名值,并赋给SESSION,但它老是提示有错.
谁能给我改改.
谢谢.
------解决方案--------------------Session session = ……;
session.setAttribute('uName', username);
不是这样么。
------解决方案--------------------X.open('POST','ajax.asp',true);
var SendData = 'username='+GE('username').value
X.send(SendData)
我一般这样写:
var SendData = 'username='+GE('username').value
X.open('POST','ajax.asp?'+SendData ,true);
X.send()
要去这个页面获取吧 你把值传给他了 'ajax.asp'
------解决方案--------------------
VBScript code
session("yhm")=request("username")
response.write("jsonUserName='"&request("username")&"';")