Ajax&Json<2>Ajax核心2
XMLHttpRequest 对象响应服务器 onreadystatechange 事件 <script type="text/javascript"> function loadName(){ var xmlHttp; if(window.XMLHttpRequest){ xmlHttp=new XMLHttpRequest(); }else{ xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); } alert("readState状态:"+xmlHttp.readyState+";status状态:"+xmlHttp.status); xmlHttp.onreadystatechange=function(){ alert("readState状态:"+xmlHttp.readyState+";status状态:"+xmlHttp.status); if(xmlHttp.readyState==4 && xmlHttp.status==200){ alert(xmlHttp.responseText); document.getElementById("name").value=xmlHttp.responseText; } }; // xmlHttp.open("get","getAjaxName?name=jack&age=11",true); // xmlHttp.open("post",true); // xmlHttp.send(); xmlHttp.open("post","getAjaxName",true); xmlHttp.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xmlHttp.send("name=jack&age=11"); } </script> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |