Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #291; incorrect this access #292

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 6 additions & 9 deletions karax/kajax.nim
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ type
FormData* {.importc.} = JsObject

HttpRequest* {.importc.} = ref object
ThisObj {.importc.} = ref object
readyState, status: int
responseText, statusText: cstring

Expand Down Expand Up @@ -50,7 +49,6 @@ proc uploadFile*(url: cstring, file: Blob, onprogress :proc(data: ProgressEvent)
cont(httpStatus, response)

proc upload(r: HttpRequest):XMLHttpRequestUpload {.importcpp: "#.upload".}
var this {.importc: "this".}: ThisObj

var formData = newFormData()
formData.append("upload_file",file)
Expand All @@ -60,8 +58,8 @@ proc uploadFile*(url: cstring, file: Blob, onprogress :proc(data: ProgressEvent)
for a, b in items(headers):
ajax.setRequestHeader(a, b)
ajax.statechange proc() =
if this.readyState == 4:
contWrapper(this.status, this.responseText)
if ajax.readyState == 4:
contWrapper(ajax.status, ajax.responseText)
ajax.upload.onprogress = onprogress
ajax.send(formData.to(cstring))

Expand All @@ -76,18 +74,17 @@ proc ajax*(meth, url: cstring; headers: openarray[(cstring, cstring)];
cont(httpStatus, response)
if doRedraw: redraw(kxi)

var this {.importc: "this".}: ThisObj

let ajax = newRequest()
ajax.open(meth, url, true)
for a, b in items(headers):
ajax.setRequestHeader(a, b)
ajax.statechange proc() =
if this.readyState == 4:
if this.status == 200:
contWrapper(this.status, this.responseText)
if ajax.readyState == 4:
if ajax.status == 200:
contWrapper(ajax.status, ajax.responseText)
else:
contWrapper(this.status, this.responseText)
contWrapper(ajax.status, ajax.responseText)
if useBinary:
ajax.send(blob)
else:
Expand Down