title>AJAX使用cookie传值例子/title>
script>
var oDiv
var xh
function getXML()
{
setcookie($('name').value,$('val').value);
oDiv = document.all.m
oDiv.innerHTML = "正在装载,请稍侯......."
oDiv.style.display= ""
xh = new ActiveXObject("Microsoft.XMLHTTP")
xh.onreadystatechange = getReady
xh.open("POST","a.php",false)
xh.send();
}
function getReady()
{
if(xh.readyState==4)
{
if(xh.status==200)
{
oDiv.innerHTML = "完成"
}
else
{
oDiv.innerHTML = "抱歉,装载数据失败。原因:" + xh.statusText
}
}
} //author : longbill www.longbill.cn
function setcookie(name,value)
{
var cookiestr=name+"="+value+";";
var expires = "";
var cookieexp=60*60*1000;
var d = new Date();
d.setTime( d.getTime() + cookieexp);
expires = "expires=" + d.toGMTString()+";";
document.cookie = cookiestr+ expires;
}
function $(a)
{
return document.getElementById(a);
}
/script>
body>
AJAX使用cookie传值例子:br>
form name=myform>
name:input id=name value="变量名甚至可以是中文" size=20>br>
value:input type=text size=20 id=val value=这里>br>
input onclick="getXML()" type="button" value="送出数据">
input onclick="if(xh xh.responseText) {alert(xh.responseText);}" type="button" value="显示返回结果">br>
div id=m bgcolor=blue>在此显示状态/div>
input type=button onclick="alert(document.cookie)" value=显示本地COOKIE>
/form>