window.onload = function(){ //获取页面元素 let orderNumberDOM = document.getElementById('orderNumber'); let userNameDOM = document.getElementById('userName'); let buttonDOM = document.getElementById('button'); let orderNumber = ''; let userName = ''; orderNumberDOM.addEventListener('change',function(){ }); } class searchOrder{ constructor(orderNumber , username){ this.orderNumber = orderNumber; this.username = username; } } class Tips{ constructor(orderNumber , username){ this.tipsContent = ''; this.type = ''; this.border = ''; this.BackgroundColor = ''; } setColor(type){ switch (type){ case 'success': this.border = '#f6ffed'; this.BackgroundColor = '1px solid #b7eb8f'; break; case 'info': this.border = '#e6f7ff'; this.BackgroundColor = '1px solid #91d5ff'; break; case 'error': this.border = '#fffbe6'; this.BackgroundColor = '1px solid #ffe58f'; break; case 'warning': this.border = '#fff2f0'; this.BackgroundColor = '1px solid #ffccc7'; break; } } } class Ajax { constructor(xhr) { xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); this.xhr = xhr; } send(options) { let xhr = this.xhr; let opt = { type: options.type || 'get', url: options.url || '', async: options.async || true, dataType: options.dataType || 'json', questring: options.questring || '' }; return new Promise((resolve, reject) => { xhr.open(opt.type, opt.url, opt.async); xhr.onreadystatechange = () => { if (xhr.readyState === 4) { if (xhr.status === 200) { if (opt.dataType === 'json') { const data = JSON.parse(xhr.responseText); resolve(data); } } else { reject(new Error(xhr.status || 'Server is fail.')); } } }; xhr.onerror = () => { reject(new Error(xhr.status || 'Server is fail.')); } xhr.setRequestHeader("Content-type","application/x-www-form-urlencoded"); xhr.send(opt.questring); }); } }