Perform an asynchronous HTTP (Ajax) request.
ajax( +http_method, +atom, -term, +ajax_options )
ajax(Method, URL, Result, Options) succeeds if Result is the response from the HTTP request sent to URL using the method Method. Method must be one of the following HTTP request methods: connect, delete, get, head, options, patch, post, put or trace. The options of the HTTP request are controlled by the options from the list Options. The available values for Options can be checked in the next section.
- type(Type). The type of data that you are expecting back from the server. If none is specified, Tau Prolog will try to infer it. Type can be text, document or json. If the request is made synchronously, this option is ignored.
- timeout(Time). Set a timeout (in milliseconds) for the request. A value of 0 means there will be no timeout. If the request is made synchronously, this option is ignored. The default value of Time is 0.
- async(Bool). Bool indicates whether or not to perform the operation asynchronously. The default value of Bool is true.
- credentials(Bool). Bool indicates whether or not cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates. The default value of Bool is false.
- mime(Mime). Mime specifies a MIME type other than the one provided by the server to be used instead when interpreting the data being transferred in a request.
- headers(List). Each memeber of List sets the value of an HTTP request header. Each member of List must be a pair Name-Value ('-'(Name, Value)), where Name and Value are atoms.
- body(Body). Body lets you specify the request's body. Body can be a list of pairs Name-Value, an atom or an HTML object from dom module (if imported).
- user(User). The optional user name to use for authentication purposes. User must be an atom.
- password(Password). The optional password to use for authentication purposes. Password must be an atom.
?- ajax(get, 'http://tau-prolog.org/files/sample/data.json', JSON, [type(json)]), json_prolog(JSON, Prolog).