Skip to content

Commit 7452d5d

Browse files
author
alxk
authored
Merge pull request #30 from mwrlabs/add-form-post
Add form post
2 parents 5cad8fc + b87fba2 commit 7452d5d

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

dref/scripts/src/libs/network.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,26 @@ export function get (url, successCb, failCb) {
3535
xhr.send()
3636
}
3737

38+
export function post (url, data, successCb, failCb) {
39+
const xhr = new XMLHttpRequest()
40+
41+
xhr.onreadystatechange = function () {
42+
if (xhr.readyState === 4) {
43+
if (xhr.status >= 200 && xhr.status < 400 && typeof successCb === 'function') {
44+
successCb(xhr.status, xhr.getAllResponseHeaders, xhr.response)
45+
} else if (typeof failCb === 'function') {
46+
failCb(xhr.status, xhr.getAllResponseHeaders(), xhr.response)
47+
}
48+
}
49+
}
50+
51+
xhr.open('POST', url, true)
52+
xhr.setRequestHeader('Pragma', 'no-cache')
53+
xhr.setRequestHeader('Cache-Control', 'no-cache')
54+
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
55+
xhr.send(data)
56+
}
57+
3858
// https://github.com/muaz-khan/DetectRTC/blob/master/DetectRTC.js
3959
export function webRTCSupported () {
4060
var supported = false;

0 commit comments

Comments
 (0)