Closed BenjyTec closed 6 months ago
Hello @BenjyTec ,
Thank you for sharing this finding. I've created an internal incident DINC0085751 for follow-up. The status of the issue will be updated here in GitHub.
Regards, Iliana
Hi @BenjyTec ,
the JSONModel.loadData function triggers the request via jQuery.ajax with the following settings object: oParameters {url: 'https://www.google.com/', async: true, dataType: 'json', cache: true, data: {…}, …} async: true cache: true data: {username: 'MyUsername', password: 'MyPassword'} dataType: "json" error: ƒ () headers: {content-type: 'application/json'} success: ƒ () type: "POST" url: "https://www.google.com/"
According to the jQuery documentation https://api.jquery.com/jQuery.ajax/#jQuery-ajax-settings the data property is: "Data to be sent to the server. If the HTTP method is one that cannot have an entity body, such as GET, the data is appended to the URL." So in your case the HTTP method is POST which can have an entity body and therefore the content of the data property does not get appended to the URL. jQuery.ajax also does not convert an object to JSON before putting it in the body but to a string that is URL encoded. We will update the documentation on the JSONModel.
Greetings, Peter.
Hi @BenjyTec
"What I meant was that a JSON object passed in is converted to the notation param1=value1¶m2=value2 instead of just being a normal JSON when put into the payload." Well it looks like jQuery.ajax does not support this. We cannot simply add this "behavior" now as it would fundamentally change the behavior of JSONModel.loadData for all users.
Greetings, Peter.
Documentation updated with SAPUI5 Version 1.122
OpenUI5 version: V1.108
Browser/version (+device/version): Chrome Version 122.0.6261.70
URL (minimal example if possible): https://plnkr.co/edit/hahwVSW7pwqYlZ8K
Steps to reproduce the problem:
JSONModel.loadData()
withoParameters
andmethod
= POSTWhat is the expected result?
I would have expected that either a) the
oParameters
always are attached to the target URL (as the official documentation indicates) b) theoParameters
are attached to the payload as JSON (and not as url-encoded String)So from my perspective there are three possible solutions:
oParameters = JSON.stringify(oParameters)
This will prevent Ajax from converting it to url-encoding.What happens instead?
The parameters passed with oParameters are put into the payload, but as url-encoded String.
Any other information? (attach screenshot if possible)
This is the Payload Section ("Nutzlast") in the Developer Tools when sending a POST request:![image](https://github.com/SAP/openui5/assets/43701845/7cf09de4-7114-4861-a1ec-c1da0ae1b982)