Module: ko/ajax

The Ajax SDK, allows you to easily send HTTP requests.

Example

require("ko/ajax").get("https://api.ipify.org", (status, text) => console.log(text));
Author:
  • ActiveState
License:
  • Mozilla Public License v. 2.0

Methods


require("ko/ajax").get(path, callback)

Query the given path/uri via a GET request

Parameters:
Name Type Description
path String

The path

callback module:ko/ajax~requestCallback

Callback function


require("ko/ajax").post(path, callback)

Query the given path/uri via a POST request

Parameters:
Name Type Description
path String

The path

callback module:ko/ajax~requestCallback

Callback function


require("ko/ajax").request(params, callback)

Manually construct a HTTP request. params can be just a URL or the full params object.

Example
params = {
     url:"",
     method:"POST|GET",
     headers:{header:"value"},
     body:"",
     withCredentials: boolean
  }
Parameters:
Name Type Description
params String | Object

url, method, headers, body, withCredentials

callback module:ko/ajax~requestCallback

Callback function

Type Definitions


requestCallback(status, responseText, request)

Parameters:
Name Type Description
status integer

Status code

responseText string

Body of the response

request XMLHttpRequest

Instance of XMLHttpRequest, see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest