用Ajax将checkbox选中的值发送给后台
生活随笔
收集整理的这篇文章主要介绍了
用Ajax将checkbox选中的值发送给后台
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
献上代码
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("发送成功");}}); });
转载于:https://www.cnblogs.com/xiaoluoli/p/5899008.html
总结
以上是生活随笔为你收集整理的用Ajax将checkbox选中的值发送给后台的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: SpringMvc和Mybatis整合需
- 下一篇: iframe框架