献上代码
var postInstall=function(data,fn){ //发送请求 var xhr = new XMLHttpRequest(); var url=""; //地址,注意不要跨域 xhr.open("post", url); xhr.setRequestHeader("content-type", "application/json"); xhr.onreadystatechange = function() { if(xhr.readyState == 4) { var str=xhr.responseText; console.log(str); var obj=JSON.parse(str); if(typeof(fn)=="function"){ fn(obj); } } } data=JSON.stringify(data); xhr.send(data); } //轮巡var Timer=setInterval(function(){ var xhr = new XMLHttpRequest(); var url=""; xhr.open("GET", url); xhr.setRequestHeader("content-type", "application/json"); xhr.onreadystatechange = function() { if(xhr.readyState == 4) { } }},2000); // 200秒内持续 document.addEventListener(‘click‘,function(evt){ if(!evt.target.matches(".yes")){ return; } var data={ //发送的数据 environ:document.getElementById("environ").checked, keystone:document.getElementById("keystone").checked, glance:document.getElementById("glance").checked, } postInstall(data,function(resdata){ if(resdata.status=="OK"){ alert("发送成功"); } }); });
时间: 2024-11-07 09:12:49