Last active
June 7, 2016 16:18
-
-
Save itsMapleLeaf/3a99f8c44e782522a5dc7f5dd34fdb1f to your computer and use it in GitHub Desktop.
lol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import querystring from 'querystring' | |
export default function request(url, params) { | |
return new Promise((resolve, reject) => { | |
const paramstring = querystring.stringify(params) | |
const request = new XMLHttpRequest | |
request.onreadystatechange = function () { | |
if (request.readyState === XMLHttpRequest.DONE) { | |
if (request.status == 200) { | |
resolve(JSON.parse(request.responseText)) | |
} | |
else { | |
reject(request.status) | |
} | |
} | |
} | |
request.open('POST', url, true) | |
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded') | |
request.send(params) | |
}) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
request("https://www.f-list.net/json/getApiTicket.php", { account, password }) | |
.then((data) => { | |
console.log(data) | |
}) | |
.catch((err) => { | |
console.error('oops', err) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment