Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core JS - Allow to send POST data as urlencoded instead of multipart form data #1452

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/main/resources/default/assets/common/core.js.pasta
Original file line number Diff line number Diff line change
Expand Up @@ -252,12 +252,19 @@ sirius.getJSON = function (url, params) {
*
* @param url the URL to invoke
* @param params the parameters to send POST data (parameters with 'undefined' values are not sent to the server)
* @param [useSearchParams] if true, the parameters are sent as URLSearchParams instead of FormData
* @returns {Promise<any>} the received JSON data
*/
sirius.postJson = function (url, params) {
sirius.postJson = function (url, params, useSearchParams) {
let body = sirius.convertObjectToFormData(params);
if (useSearchParams) {
// Convert the body to URLSearchParams, this may be necessary when using problematic characters in field names
// that are converted/replaced by the multipart decoder of Netty.
body = new URLSearchParams(body);
}
return fetch(url, {
method: "post",
body: sirius.convertObjectToFormData(params)
body: body
}).then(function (response) {
return response.json();
});
Expand Down