The Ajax SDK, allows you to easily send HTTP requests.
Example
require("ko/ajax").get("https://api.ipify.org", (status, text) => console.log(text));
- Copyright:
-
- (c) 2017 ActiveState Software Inc.
- 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 pathString The path
callbackmodule:ko/ajax~requestCallback Callback function
-
require("ko/ajax").post(path, callback)
-
Query the given path/uri via a POST request
Parameters:
Name Type Description pathString The path
callbackmodule:ko/ajax~requestCallback Callback function
-
require("ko/ajax").request(params, callback)
-
Manually construct a HTTP request.
paramscan 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 paramsString | Object url, method, headers, body, withCredentials
callbackmodule:ko/ajax~requestCallback Callback function
Type Definitions
-
requestCallback(status, responseText, request)
-
Parameters:
Name Type Description statusinteger Status code
responseTextstring Body of the response
requestXMLHttpRequest Instance of XMLHttpRequest, see https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest