-
Notifications
You must be signed in to change notification settings - Fork 3
/
xmlhttprequest.go
64 lines (50 loc) · 1.31 KB
/
xmlhttprequest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package tinydom
import "syscall/js"
type XMLHttpRequest struct {
js.Value
}
func NewXMLHttpRequest() *XMLHttpRequest {
return &XMLHttpRequest{GetWindow().Get("XMLHttpRequest").New()}
}
func (x *XMLHttpRequest) ResponseText() string {
return x.Get("responseText").String()
}
func (x *XMLHttpRequest) ResponseURL() string {
return x.Get("responseURL").String()
}
func (x *XMLHttpRequest) ResponseXML() *Element {
return &Element{x.Get("responseXML")}
}
func (x *XMLHttpRequest) StatusText() string {
return x.Get("statusText").String()
}
func (x *XMLHttpRequest) WithCredentials() bool {
return x.Get("withCredentials").Bool()
}
func (x *XMLHttpRequest) SetWithCredentials(c bool) {
x.Set("withCredentials", c)
}
func (x *XMLHttpRequest) Abort() {
x.Call("abort")
}
func (x *XMLHttpRequest) Open(method, url string, args ...interface{}) {
if len(args) == 1 {
// args[0] should be bool async
x.Call("open", method, url, args[0])
} else {
x.Call("open", method, url)
}
}
func (x *XMLHttpRequest) OverrideMimeType(mimeType string) {
x.Call("overrideMimeType", mimeType)
}
func (x *XMLHttpRequest) Send(args ...interface{}) {
if len(args) == 1 {
x.Call("send", args[0])
} else {
x.Call("send")
}
}
func (x *XMLHttpRequest) SetRequestHeader(header, value string) {
x.Call("setRequestHeader", header, value)
}