24 lines
674 B
TypeScript
24 lines
674 B
TypeScript
|
|
export default{
|
|
hosturl:"http://127.0.0.1:8080",
|
|
sendAjax(url:string,data:object,method:string,callback:Function){
|
|
let xhr = new XMLHttpRequest();
|
|
xhr.open(method,this.hosturl+url,true)
|
|
let token = localStorage.getItem('token')
|
|
if(token){
|
|
// console.log(token);
|
|
|
|
xhr.setRequestHeader("Authorization",token)
|
|
}
|
|
let params = JSON.stringify(data)
|
|
xhr.send(params)
|
|
xhr.onreadystatechange = () =>{
|
|
if (xhr.readyState==4 &&xhr.status==200) {
|
|
let res = JSON.parse(xhr.responseText)
|
|
callback(res)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|