- let data_str = "";
- Object.keys(data).forEach(k => {
- data_str += k + "=" + encodeURIComponent(data[k]) + "&";
- });
- return data_str.slice(0, -1); //remove last "&"
+ let data_str = "";
+ Object.keys(data).forEach(k => {
+ data_str += k + "=" + encodeURIComponent(data[k]) + "&";
+ });
+ return data_str.slice(0, -1); //remove last "&"
}
// data, error: optional
export function ajax(url, method, data, success, error)
{
}
// data, error: optional
export function ajax(url, method, data, success, error)
{
- if (!error)
- error = errmsg => { alert(errmsg); };
- xhr.onreadystatechange = function() {
- if (this.readyState == 4 && this.status == 200)
- {
+ if (!error)
+ error = errmsg => { alert(errmsg); };
+ xhr.onreadystatechange = function() {
+ if (this.readyState == 4 && this.status == 200)
+ {
- if (["GET","DELETE"].includes(method) && !!data)
- {
- // Append query params to URL
- url += "/?" + toQueryString(data);
- }
- xhr.open(method, params.serverUrl + url, true);
- xhr.setRequestHeader('X-Requested-With', "XMLHttpRequest");
- // Next line to allow cross-domain cookies in dev mode (TODO: if...)
+ if (["GET","DELETE"].includes(method) && !!data)
+ {
+ // Append query params to URL
+ url += "/?" + toQueryString(data);
+ }
+ xhr.open(method, params.serverUrl + url, true);
+ xhr.setRequestHeader('X-Requested-With', "XMLHttpRequest");
+ // Next line to allow cross-domain cookies in dev mode (TODO: if...)
if (params.cors)
xhr.withCredentials = true;
if (["POST","PUT"].includes(method))
if (params.cors)
xhr.withCredentials = true;
if (["POST","PUT"].includes(method))
- {
- xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
- xhr.send(JSON.stringify(data));
- }
- else
- xhr.send();
+ {
+ xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
+ xhr.send(JSON.stringify(data));
+ }
+ else
+ xhr.send();