STAT.ajax
STAT GET | stat.ajax.get(url, {params}, callback);
@param {string} url : path to endpoint
@param {object} params : params to send in URL
@callback {function} callback to run when readyState == 4
Example Params as object:
const aggParams = {
username: 'utahgov',
count: 4
}
Example with Callback:
stat.ajax.get('/aggregator/tweetsForUser.json', aggParams, ajax_callback);
STAT POST | stat.ajax.post(url, {params}, callback);
@param {string} url : path to endpoint
@param {object} params : body
@callback {function} callback to run when readyState == 4
example:
stat.ajax.post(url, {name: 'bob', title: 'foo'}, function(xhr) {
console.log(xhr.response);
});
Setting custom request headers
Setting a custom header is done by passing a specific object into the existing {params} object
@param {object} params: {setRequestHeader: {a:b, x:y}};
example:
const myParams: {
location: 'foo',
count: 10,
setRequestHeader: {
'x-captcha-verification': 'abcxyz0123',
'x-another-custom-header': 'My Header'
}
}
STAT.ajax will detect the 'setRequestHeader' object, strip it from the request params and apply it to the request header automatically.
Setting custom responseType
Setting a custom header is done by passing a specific key:value into the existing {params} object.
@param {object} params: {responseType: 'text'};
example:
const myParams: {
location: 'foo',
count: 10,
responseType: 'text'
}
STAT.ajax will detect the 'responseType' key, strip it from the request params and apply it to the request automatically.