src/fusion/js/jsxmlhttprequest

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

Example:

import src/fusion/js/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
  withCredentials*: bool
  status*, timeout*, readyState*: cint
  responseText*, responseURL*, statusText*: cstring
https://xhr.spec.whatwg.org

Procs

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