<!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
>
<html>
<head>
<meta http-equiv=
"Content-Type"
content=
"text/html; charset=gb2312"
>
<title>ajax post test</title>
</head>
<body>
<div id=
"msg"
></div>
<script language=
"javascript"
>
function
InitAjax()
{
var
ajax=false;
try
{
ajax =
new
ActiveXObject(
"Msxml2.XMLHTTP"
);
}
catch
(e) {
try
{
ajax =
new
ActiveXObject(
"Microsoft.XMLHTTP"
);
}
catch
(E) {
ajax = false;
}
}
if
(!ajax && typeof XMLHttpRequest!='undefined') {
ajax =
new
XMLHttpRequest();
}
return
ajax;
}
function
sendData()
{
var
msg=document.getElementById(
"msg"
);
var
f=document.form1;
var
c=f.content.value;
var
url=
"dispmsg.php"
;
var
poststr=
"content="
+c;
var
ajax=InitAjax();
ajax.open(
"POST"
,url,true);
ajax.setRequestHeader(
"Content-Type"
,
"application/x-www-form-urlencoded"
);
ajax.send(poststr);
ajax.onreadystatechange=
function
(){
if
(ajax.readyState==4 && ajax.status==200){
alert(
"I got something"
);
msg.innerHTML=ajax.resp****eText;
}
}
}
</script>
<form name='form1'>
<input type=
"text"
name='content' size=10>
<input type=
"button"
value=
"确定"
οnclick=
"sendData()"
><!--我用submit时就出错-->
</form>
</body>
</html>