首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Ajax >

onreadystatechange没有执行解决办法

2012-05-22 
onreadystatechange没有执行htmlheadmeta http-equivcontent-type contenttext/htmlcharsetgb

onreadystatechange没有执行
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=gb2312">
<script type="text/javascript">
function up()
{
var xmlHttp;
if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
} else 
{
xmlHttp = new ActiveXObject("Microsoft.XMLHttp");
}
xmlHttp.open("post","ajax01.php",true);
xmlHttp.onreadystatechange=changed;
alert(xmlHttp.readyState);
xmlhttp.send();
alert(xmlHttp.readyState);
}
function changed()
{
if(xmlHttp.readyState=4 || xmlHttp.status=200)
{
alert(5);
var value = document.getElementById("input1").value;
}
}
</script>
</head>
<body>
<form>
username:<input id="input1" name="username" /><br>
<input type="submit" value="OK" onclick="up()" />
</form>
</body>
</html>

ajax01.php代码:
<?php
echo("hello world!");
?>
[code=HTML][/code]

[解决办法]

HTML code
<html><head><meta http-equiv="content-type" content="text/html;charset=gb2312"><script type="text/javascript">var xmlHttp;function up(){if(window.XMLHttpRequest){xmlHttp = new XMLHttpRequest();} else  {xmlHttp = new ActiveXObject("Microsoft.XMLHttp");}xmlHttp.onreadystatechange=changed;xmlHttp.open("post","ajax01.php",true);xmlHttp.send();}function changed(){if(xmlHttp.readyState==4 && xmlHttp.status==200){alert(5);var value = document.getElementById("input1").value;}}</script></head><body><form>username:<input id="input1" name="username" /><br><input type="button" value="OK" onclick="up()" /></form></body></html> 

热点排行