Skip to content
Snippets Groups Projects
Commit 412dbe0d authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by Jan-Hendrik Willms
Browse files

fix encoding of data passed to STUDIP.jsonapi request methods, fixes #984

Closes #984

Merge request studip/studip!566
parent f310c5b7
No related branches found
No related tags found
Loading
......@@ -30,7 +30,7 @@ class AbstractAPI
this.base_url = base_url;
}
encodeData (data) {
encodeData (data, method) {
if (data instanceof Function) {
data = data();
}
......@@ -76,7 +76,7 @@ class AbstractAPI
deferred = $.ajax(STUDIP.URLHelper.getURL(`${this.base_url}/${url}`, {}, true), {
contentType: options.contentType || 'application/x-www-form-urlencoded; charset=UTF-8',
method: options.method.toUpperCase(),
data: this.encodeData(options.data),
data: this.encodeData(options.data, options.method.toUpperCase()),
headers: options.headers
}).always(() => {
// Decrease request counter, remove overlay if neccessary
......
......@@ -7,9 +7,13 @@ class JSONAPI extends AbstractAPI
super(`jsonapi.php/v${version}`);
}
encodeData (data) {
encodeData (data, method) {
data = super.encodeData(data);
if (['DELETE', 'GET', 'HEAD'].includes(method)) {
return data;
}
if (Object.keys(data).length === 0) {
return null;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment