84487600 2019-07-01
/** * 通过dom构建表单 * @param hidData Object { 'account': 'show tables ;'} ; * @param url * @param frame * @param method */ init.dom = function (hidData,url,method) { if(!hidData) return ; if(!method) method = 'post' ; var f = document.createElement("form"); document.body.appendChild(f); for( var i in hidData ) { var temp = document.createElement("input"); temp.type = "hidden"; f.appendChild(temp); temp.value = hidData[i]; temp.name = i ; } /*JSON.stringify() JSON.parse()*/ f.action = url; f.method = method; f.submit(); }; /** * 设置 header 表单 * @param data * @param url * @param header * @param method */ init.herderDom = function (data,url,header,method) { if(!data) return ; if(!method) method = 'POST'; //xml对象 var xmlhttp = new XMLHttpRequest(); //目标地址 xmlhttp.open(method, url,true); //设置header if(header) { for( var i in header ) { xmlhttp.setRequestHeader(i, header[i]); } } xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); //数据设置 var content = ''; for (var d in data) { content += '&'+d+'='+data[d] ; } xmlhttp.send(content) ; //内容格式根据Content-type设置的格式而定 xmlhttp.onreadystatechange = function(){ if(xmlhttp.readyState == 4 && xmlhttp.status == 200){ //成功 console.log(xmlhttp.responseText); } } };