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

Cannot set onerror handler #3

Closed
halloleo opened this issue Apr 20, 2021 · 0 comments · Fixed by #5
Closed

Cannot set onerror handler #3

halloleo opened this issue Apr 20, 2021 · 0 comments · Fixed by #5

Comments

@halloleo
Copy link

When I try to set an onerror handler on an httpRequest I get a type mismatch.

Here the details. The Nim code is:

import dom
import ajax

proc makeRequest(url:cstring) =
  var httpRequest = newXMLHttpRequest()

  proc alertContents(e:Event) =
    if httpRequest.readyState == rsDONE:
      if httpRequest.status == 200:
        window.alert(httpRequest.responseText)
      else:
        window.alert("There was a problem with the request.")
  proc alertError(e:Event) =
        window.alert("There was a FUNDAMENTAL problem with the request.")

  httpRequest.onreadystatechange = alertContents
  httpRequest.onerror = alertError
  httpRequest.open("GET", url);
  httpRequest.send();

document.getElementById("ajaxButton").onclick = proc(e:Event) =
  makeRequest("test.html")

The full error message of the compiler is:

Error: type mismatch: got <XMLHttpRequest, proc (e: Event){.noSideEffect, gcsafe, locks: 0.}>
but expected one of: 
macro `.=`(obj: JsObject; field, value: untyped): untyped
  first type mismatch at position: 1
  required type for obj: JsObject
  but expression 'httpRequest' is of type: XMLHttpRequest
macro `.=`[K: cstring; V](obj: JsAssoc[K, V]; field: untyped; value: V): untyped
  first type mismatch at position: 1
  required type for obj: JsAssoc[.=.K, .=.V]
  but expression 'httpRequest' is of type: XMLHttpRequest
@stisa stisa linked a pull request Oct 28, 2021 that will close this issue
@stisa stisa closed this as completed in #5 Oct 28, 2021
stisa added a commit that referenced this issue Oct 28, 2021
add onerror handler
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant