<script type="text/javascript">
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
try
{
return new ActiveXObject("MSxml2.XMLHTTP");
}catch(e)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
else if(window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
}
function exec1(v)
{
var xhr=createXMLHttpRequest();
xhr.onreadystatechange=function()
{
if(xhr.readyState==4 && xhr.status==200)
{
document.getElementById("showUser").innerHTML=xhr.responseText;
}
};
xhr.open("post","<%=path%>/getValue.jsp",true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("deptid="+v);
}
</script>
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
try
{
return new ActiveXObject("MSxml2.XMLHTTP");
}catch(e)
{
return new ActiveXObject("Microsoft.XMLHTTP");
}
}
else if(window.XMLHttpRequest)
{
return new XMLHttpRequest();
}
}
function exec1(v)
{
var xhr=createXMLHttpRequest();
xhr.onreadystatechange=function()
{
if(xhr.readyState==4 && xhr.status==200)
{
document.getElementById("showUser").innerHTML=xhr.responseText;
}
};
xhr.open("post","<%=path%>/getValue.jsp",true);
xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhr.send("deptid="+v);
}
</script>
本文介绍了一种使用XMLHttpRequest对象实现异步POST请求的方法。通过JavaScript代码展示了如何创建XMLHttpRequest实例,并发送POST请求到特定的JSP文件。此外,还介绍了如何处理响应并更新页面元素的内容。
711

被折叠的 条评论
为什么被折叠?



