Skip to content
Snippets Groups Projects
Commit 1dad7aab authored by Jan-Hendrik Willms's avatar 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 cc54019c
No related branches found
No related tags found
No related merge requests found
...@@ -30,7 +30,7 @@ class AbstractAPI ...@@ -30,7 +30,7 @@ class AbstractAPI
this.base_url = base_url; this.base_url = base_url;
} }
encodeData (data) { encodeData (data, method) {
if (data instanceof Function) { if (data instanceof Function) {
data = data(); data = data();
} }
...@@ -76,7 +76,7 @@ class AbstractAPI ...@@ -76,7 +76,7 @@ class AbstractAPI
deferred = $.ajax(STUDIP.URLHelper.getURL(`${this.base_url}/${url}`, {}, true), { deferred = $.ajax(STUDIP.URLHelper.getURL(`${this.base_url}/${url}`, {}, true), {
contentType: options.contentType || 'application/x-www-form-urlencoded; charset=UTF-8', contentType: options.contentType || 'application/x-www-form-urlencoded; charset=UTF-8',
method: options.method.toUpperCase(), method: options.method.toUpperCase(),
data: this.encodeData(options.data), data: this.encodeData(options.data, options.method.toUpperCase()),
headers: options.headers headers: options.headers
}).always(() => { }).always(() => {
// Decrease request counter, remove overlay if neccessary // Decrease request counter, remove overlay if neccessary
......
...@@ -7,9 +7,13 @@ class JSONAPI extends AbstractAPI ...@@ -7,9 +7,13 @@ class JSONAPI extends AbstractAPI
super(`jsonapi.php/v${version}`); super(`jsonapi.php/v${version}`);
} }
encodeData (data) { encodeData (data, method) {
data = super.encodeData(data); data = super.encodeData(data);
if (['DELETE', 'GET', 'HEAD'].includes(method)) {
return data;
}
if (Object.keys(data).length === 0) { if (Object.keys(data).length === 0) {
return null; 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