DubZ
DubZ

Reputation: 582

JSONModel loaddata post data in http body

I tried to find out if there is really no way with JSONModel loaddata to do a HTTP post adding data (string/binary) to the http body.

While reading the docs (https://openui5.hana.ondemand.com/api/sap.ui.model.json.JSONModel#methods/Summary), testing and searching in stackoverflow/google it seems that there is no way?

I know that I can achieve it with default javascript/jquery ajax. The question is if it's also possible with loaddata method and if I missed something.

Upvotes: 1

Views: 1344

Answers (1)

Marc
Marc

Reputation: 6190

I dug a little deeper and noticed that loadData calls jQuery.ajax at some point.

https://github.com/SAP/openui5/blob/c782ce9be8cbd71201e19ba3cb4c0e81e439b71f/src/sap.ui.core/src/sap/ui/model/ClientModel.js#L130

So I tried the following

const oModel = new JSONModel();
oModel.loadData("https://httpbin.org/post", { key: "value" }, true, "POST");

This was the request body

enter image description here

and the response

enter image description here

Isn't this exactly what you are looking for?

Upvotes: 0

Related Questions