function ajax(options) { var options = options || {}; options.type = (options.type || 'GET').toUpperCase(); options.dataType = options.dataType || 'json'; params = formatParams(options.data); //创建-第一步 var xhr; //非IE6 if (window.XMLHttpRequest) { xhr = new XMLHttpRequest(); } else { //ie6及其以下版本浏览器 xhr = ActiveXObject('Microsoft.XMLHTTP'); } //接收-第三步 xhr.onreadystatechange = function () { if (xhr.readyState == 4) { var status = xhr.status; if (status >= 200 && status < 300) { options.success && options.success(xhr.responseText, xhr.responseXML); } else { options.error && options.error(status); } } } //连接和发送-第二步 if (options.type == 'GET') { xhr.open('GET', options.url + '?' + params, true); xhr.send(null); } else if (options.type == 'POST') { xhr.open('POST', options.url, true); //设置表单提交时的内容类型 xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.send(params); }else if (options.type == 'HEAD') { xhr.open('Head', options.url + '?' + params, true); xhr.send(null); } } //格式化参数 function formatParams(data) { var arr = []; for (var name in data) { arr.push(encodeURIComponent(name) + '=' + encodeURIComponent(data[name])); } // arr.push(('v='+Math.random()).replace('.','')); return arr.join('&'); } function OpenDwSource() { var host = "http://localhost:19882" var xsource = '
'; xsource += '
'; xsource += '

请选择扫描仪:

'; xsource += '
'; xsource += '
    '; xsource += '
'; xsource += '
'; var sourcediv = document.createElement("div") sourcediv.id = "xscanner-model" sourcediv.innerHTML = xsource; document.getElementsByTagName("body")[0].appendChild(sourcediv) // ajax({ url: host + '/xscanSourceList.aspx', type: 'get', dataType: 'json', data: {}, success: function (response, xml) { var listr = "" JSON.parse(response).forEach((item, index) => { if (index == 0) { listr += "
  • " + item + "
  • "; } else { listr += "
  • " + item + "
  • "; } }) document.getElementById("xscanner-sourcelist").children[0].innerHTML = listr; }, error: function (status) { //失败后执行的代码 } }); // 确定 document.getElementById("xscanner-confirm-btn").addEventListener("click", function () { ajax({ url: host + '/xscanAction.aspx', type: 'GET', dataType: 'json', data:{tid:123}, success: function (response, xml) { if (response) { } }, error: function (status) { //失败后执行的代码 } }); var last = null; var counter = "15982" var i = 0; var timer = window.setInterval(function () { i += 1 var xscannercontainer = document.getElementById("XScannerContainer") xscannercontainer.style = "overflow:scroll;padding:10px 20px 20px 20px;" last = xscannercontainer.firstChild; ajax({ url: host + '/xscanImgUri.aspx', type: 'GET', dataType: 'json', data: {t:new Date().getTime()}, success: function (response, xml) { console.log(response) if (response) { response.split(",").forEach((item,index)=>{ var img = document.createElement("img") img.src = host + "/xscanImgReview.aspx?imgid="+item img.style = "width:100%;margin-bottom:10px;" if (last) { xscannercontainer.insertBefore(img, last) } else { xscannercontainer.append(img) } }) } }, error: function (status) { //失败后执行的代码 } }); }, 1000) document.getElementById("xscanner-model").remove(); }) // 取消 document.getElementById("xscanner-cancel-btn").addEventListener("click", function () { document.getElementById("xscanner-model").remove(); }) }