src/nodejs/jsxmlhttprequest

XMLHttpRequest for the JavaScript target: https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

Example:

import src/nodejs/jsxmlhttprequest
from std/dom import Node
if defined(fusionJsXmlhttprequestTests):
  let request: XMLHttpRequest = newXMLHttpRequest()
  request.open("GET".cstring, "http://localhost:8000/".cstring, false)
  request.setRequestHeader("mode".cstring, "no-cors".cstring)
  request.setRequestHeader([(key: "mode".cstring, val: "no-cors".cstring)])
  request.overrideMimeType("text/plain".cstring)
  request.send()
  echo request.getAllResponseHeaders()
  echo "responseText\t", request.responseText
  echo "responseURL\t", request.responseURL
  echo "statusText\t", request.statusText
  echo "responseXML\t", request.responseXML is Node
  echo "status\t", request.status
  echo "timeout\t", request.timeout
  echo "withCredentials\t", request.withCredentials
  echo "readyState\t", request.readyState
  request.abort()

Types

XMLHttpRequest = ref object of JsRoot
  responseXML*: Node
  responseType*: cstring
  withCredentials*: bool
  status*, timeout*, readyState*: cint
  responseText*, responseURL*, statusText*: cstring
https://xhr.spec.whatwg.org

Procs

func abort(this: XMLHttpRequest) {.importjs: "#.$1()", ...raises: [], tags: [].}
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/abort
func newXMLHttpRequest(): XMLHttpRequest {.importjs: "new XMLHttpRequest()",
    ...raises: [], tags: [].}
Constructor for XMLHttpRequest.
func open(this: XMLHttpRequest; metod, url: cstring; async = true;
          user = cstring.default; password = cstring.default) {.
    importjs: "#.$1(#, #, #, #, #)", ...raises: [], tags: [].}
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/open
func overrideMimeType(this: XMLHttpRequest; mimeType: cstring) {.
    importjs: "#.$1(#)", ...raises: [], tags: [].}
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/overrideMimeType
func send(this: XMLHttpRequest; body: cstring | Node = cstring.default) {.
    importjs: "#.$1(#)", ...raises: [], tags: [].}
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/send
func setRequestHeader(this: XMLHttpRequest;
                      keyValuePairs: openArray[tuple[key, val: cstring]]) {.
    ...raises: [], tags: [].}
Same as setRequestHeader but takes openArray[tuple[key, val: cstring]].
func setRequestHeader(this: XMLHttpRequest; key, value: cstring) {.
    importjs: "#.$1(#, #)", ...raises: [], tags: [].}
https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/setRequestHeader