var ajax = function (token) {
return new Promise(function(resolve,reject){
var xhr = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject('Microsoft.XMLHTTP');
var url = '';
var obj = {'accessToken':token}
var params = "request="+JSON.stringify(obj);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if (xhr.status >= 200 && xhr.status < 300) {
var res = JSON.parse(xhr.responseText);
if (res.code == 0) {
resolve(res.response.userId)
}else {
reject(res.msg)
}
} else {
alert('error')
}
}
}
xhr.open('POST', url, true);
xhr.setRequestHeader('Content-type', "application/x-www-form-urlencoded");
xhr.send(params);
})
},
ajax(token).then(function(res){
sessionStorage.setItem('userid',res);
}).catch(function(res){
console.log(res)
})
网友评论