Skip to content

Instantly share code, notes, and snippets.

@itsMapleLeaf
Last active June 7, 2016 16:18
Show Gist options
  • Save itsMapleLeaf/3a99f8c44e782522a5dc7f5dd34fdb1f to your computer and use it in GitHub Desktop.
Save itsMapleLeaf/3a99f8c44e782522a5dc7f5dd34fdb1f to your computer and use it in GitHub Desktop.
lol
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)
})
}
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