Examples:
// make simple request
Ajax.request('/your/url')
.get({some: 'data'})
.do(result=>{
console.log(result);
});
// store request for later call
let request = Ajax.request('/your/url')
.get({some: 'data'})
.callback(result=>{
console.log(result);
});
request.do();
// using as promise
function doMyRequest(data){
let myRequest = Ajax.request('/your/url')
.get(data)
.promise();
return myRequest;
}
doMyRequest(data).then(result=>{
console.log(result);
});
// insted of "get" you can also use the following methods:
// - get(data): GET request, data as URL data
// - post(data): POST request, data as FormData
// - postJSON(data): POST request, data as json payload
// - delete(data): DELETE request, data as FormData
// - deleteJSON(data): DELETE request, data as json payload
// - put(data): PUT request, data as FormData
// - putJSON(data): PUT request, data as json payload
// - upload(data, file): POST request, data as FormData
// The result is an AjaxResult object, which contains the following fields:
// - request: the raw XMLHttpRequest
// - status: HTTP status code
// - statusText: HTTP status text
// - response: an appropriate object based on the response type (https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/response)
// - responseText: raw text response
// - json: tries to json parse the responseText. On parse error returns undefined. (Use the response field instead!)