日期:2014-05-16 浏览次数:20639 次
<html> <head> <title>createAjax.html</title> </head> <body> <script language="Javascript"> var xmlHttp; function createXMLHttp(){ if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); }else{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } } function showMsg(){ xmlHttp.open("POST","content.html"); xmlHttp.onreadystatechange=showMsgCallback(); xmlHttp.send(null); } function showMsgCallback(){ if(xmlHttp.readyState == 4){ if(xmlHttp.status == 200){ var text=xmlHttp.responseText; document.getElementById("msg").className="样式表名称"; document.getElementById("msg").innerHTML=text; } } } </script> <input type="button" onclick="showMsg()" value="调用AJAX显示内容"/> <span id="msg"></span> </body> </html>
hello world!!!
function showMsg(){ xmlHttp.open("POST","content.html"); //xmlHttp.onreadystatechange=showMsgCallback(); xmlHttp.onreadystatechange=showMsgCallback;//这句才是正确的写法,去掉了showMsgCallback后的括号 xmlHttp.send(null); }
------解决方案--------------------
除了楼上各位的建议,楼主可以看看你的createXMLHttp()好像就没用到,这应该是个失误吧