ajax與js


<head>
<script type="text/javascript">
var xmlhttp = false;
function CreateXMLHttp(){
try{
xmlhttp = new XMLHttpRequest();
}
catch (e){
try{
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e){
try{
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (failed){
xmlhttp = false;
}
}
}
return xmlhttp;
}
xmlhttp = CreateXMLHttp();
xmlhttp.open("post","a.html",true);
xmlhttp.onReadyStateChange = getResult;
xmlhttp.send();
function getResult(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
alert(xmlhttp.responseText);
}
}
</script>
</head>
</html>


<html>
<head>
<script type="text/javascript">
var xmlhttp;
function showHint(){
alert(xmlhttp+"1");
alert((undefined == xmlhttp)+"2");
alert((null == xmlhttp)+"3");
alert(("" == xmlhttp)+"4");
return xmlhttp;
}
</script>
</head>
<body>
<form>
First Name:<input type="text" id="txt1" οnkeyup="showHint()" />
</form>
<p>Suggestions: <span id="txtHint"></span></p>
</body>
</html>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章