ajax post方法如何放松数据
1.index.html文件<!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3....
1.index.html文件
<!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>
<script type="text/javascript">
function ajaxLoad(){
var xmlHttp=false;
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
xmlHttp.overrideMimeType("application/x-www-form-urlencoded");
}
if(window.ActiveXObject){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("您的浏览器不支持AJAX");
}
}
if(xmlHTTP){
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
}
xmlHttp.open("POST","ajax.asp");
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4&&xmlHttp.status==200){
document.getElementById("block").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.send("username=dashu");
}
</script>
</head>
<body>
<span id="block"></span>
<a onclick="ajaxLoad();">Click</a>
</body>
</html>
2.ajax.asp
<%
response.write request.Form("username")
%>
运行以上代码,没有任何结果,请高手指点 展开
<!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>
<script type="text/javascript">
function ajaxLoad(){
var xmlHttp=false;
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
xmlHttp.overrideMimeType("application/x-www-form-urlencoded");
}
if(window.ActiveXObject){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("您的浏览器不支持AJAX");
}
}
if(xmlHTTP){
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
}
}
xmlHttp.open("POST","ajax.asp");
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4&&xmlHttp.status==200){
document.getElementById("block").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.send("username=dashu");
}
</script>
</head>
<body>
<span id="block"></span>
<a onclick="ajaxLoad();">Click</a>
</body>
</html>
2.ajax.asp
<%
response.write request.Form("username")
%>
运行以上代码,没有任何结果,请高手指点 展开
1个回答
展开全部
1. if(xmlHTTP){ 应为 if(xmlHttp){
2. xmlHttp.open("POST","ajax.asp");
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 这两行的顺序不能颠倒。也就是说要在xmlHttp.open后再调用setRequestHeader
以下是改好的代码:
<!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>
<script type="text/javascript">
function ajaxLoad(){
var xmlHttp=false;
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
xmlHttp.overrideMimeType("application/x-www-form-urlencoded");
}
if(window.ActiveXObject){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("您的浏览器不支持AJAX");
}
}
if(xmlHttp){
xmlHttp.open("POST","ajax.asp");
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4&&xmlHttp.status==200){
document.getElementById("block").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.send("username=dashu");
}
}
}
</script>
</head>
<body>
<span id="block"></span>
<a onclick="ajaxLoad();">Click</a>
</body>
</html>
2. xmlHttp.open("POST","ajax.asp");
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); 这两行的顺序不能颠倒。也就是说要在xmlHttp.open后再调用setRequestHeader
以下是改好的代码:
<!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>
<script type="text/javascript">
function ajaxLoad(){
var xmlHttp=false;
if(window.XMLHttpRequest){
xmlHttp=new XMLHttpRequest();
xmlHttp.overrideMimeType("application/x-www-form-urlencoded");
}
if(window.ActiveXObject){
try{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}catch(e){
try{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}catch(e){
alert("您的浏览器不支持AJAX");
}
}
if(xmlHttp){
xmlHttp.open("POST","ajax.asp");
xmlHttp.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
xmlHttp.onreadystatechange=function(){
if(xmlHttp.readyState==4&&xmlHttp.status==200){
document.getElementById("block").innerHTML=xmlHttp.responseText;
}
}
xmlHttp.send("username=dashu");
}
}
}
</script>
</head>
<body>
<span id="block"></span>
<a onclick="ajaxLoad();">Click</a>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询