纯js发送ajax请求
每次都用jquery,这次要微信开发,用纯js的可能少加载点东西,再次做个记录,只是ajax的部分代码
<script> var XMLHttpReq; //异步请求 var url = "checkNum?phoneNum="+hPhoneNum+"&checkNum="+checkNum; createXMLHttpRequest(); XMLHttpReq.open("post", url, true); XMLHttpReq.onreadystatechange =function(){ var msg = XMLHttpReq.responseText; if (msg == "ok") { checkNums.innerHTML="ok"; checkNums.style.color = "green"; document.getElementById("checkNumForm").submit(); } else { checkNums.innerHTML="验证码无效"; checkNums.style.color ="red"; return; } }; XMLHttpReq.send(null); // 创建xml请求 function createXMLHttpRequest() { try { XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");//IE高版本创建XMLHTTP } catch(E) { try { XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");//IE低版本创建XMLHTTP } catch(E) { XMLHttpReq = new XMLHttpRequest();//兼容非IE浏览器,直接创建XMLHTTP对象 } } } </script>
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05