/** * * * * * * */ function get(url){ return new Promise((resolve,reject)=>{ var xhr = new XMLHttpRequest() xhr.open('GET', url, true) xhr.onreadystatechange = function(){ if(this.readyState === 4){ if(this.readyState === 200){ resolve(this.responseText,this) }else{ var reJson = {code:this.status, response:this.response} reject(reJson. this) } } } xhr.send() }) } //general get function getFunction(url,callback){ url =url const xhr = new XMLHttpRequest() xhr.onreadystatechange = () => { if ((xhr.readyState === 4 && xhr.status === 200 && xhr.status <= 300) || xhr.status === 304) { data = xhr.responseText callback(data) }} xhr.open('GET', url, true) xhr.setRequestHeader("If-Modified-Since","0") xhr.send() } //general post function postFunction(url, reback,data) { const xhr = new XMLHttpRequest(); xhr.onreadystatechange = function (){ if ( xhr.status === 200 && xhr.readyState === 4 ) { // console.log("post response status is",xhr.responseText) reback(xhr.responseText); } else { // console.log("xhr state is", xhr.status); } } xhr.open("POST", url, true); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8"); // xhr.setRequestHeader("Content-Type", "application/application/wasm;charset=UTF-8"); // xhr.setRequestHeader("Access-Control-Allow-Origin: *"); // xhr.setRequestHeader("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE"); // xhr.setRequestHeader("Access-Control-Allow-Headers: X-Requested-With, Content-Type"); xhr.send(data); } //put promise function postPromise(url, data) { return new Promise((resolve, reject)=>{ var xhr = new XMLHttpRequest() xhr.open("POST", url, true) // xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); // xhr.setRequestHeader("Content-Type", "application/application/wasm; charset=UTF-8"); // xhr.setRequestHeader("Access-Control-Allow-Origin: *"); // xhr.setRequestHeader("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE"); // xhr.setRequestHeader("Access-Control-Allow-Headers: X-Requested-With, Content-Type"); xhr.onreadystatechange = function () { if (this.readyState === 4) { if (this.status === 200) { // resolve(JSON.parse(this.responseText), this) resolve(this.responseText) } else { // var resJson = { code: this.status, response: this.response } // reject(resJson, this) reject(this.status) } } } xhr.send(data) }) } //put promise function putPromise(url, data) { return new Promise((resolve, reject)=>{ var xhr = new XMLHttpRequest() xhr.open("PUT", url, true) // xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); xhr.setRequestHeader("Content-Type", "application/application/wasm; charset=UTF-8"); // xhr.setRequestHeader("Access-Control-Allow-Origin: *"); // xhr.setRequestHeader("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE"); // xhr.setRequestHeader("Access-Control-Allow-Headers: X-Requested-With, Content-Type"); xhr.onreadystatechange = function () { if (this.readyState === 4) { if (this.status === 200) { // resolve(JSON.parse(this.responseText), this) resolve(this.responseText) } else { // var resJson = { code: this.status, response: this.response } // reject(resJson, this) reject(this.status) } } } xhr.send(data) }) }