cancel
Showing results for 
Search instead for 
Did you mean: 

How to replace ajax call with ODataModel?

Former Member
0 Kudos

Hi,

I am new to SAP UI5. I went through the ODataModel api. All I found is, if we want to make use of the ODataModel, we are supposed to bind the model to some control. But what about the cases where we don't want to bind the results we get from the request to server to any of the controls?

Is there any way/method present which would help us to retrieve the data without binding the model to any of the controls?

Any help would be appreciated.

Thanks,

Supriya Kale

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi there,

I don't really understand your problem...

What do you mean with "repalce ajax call"? If you want to retrieve data form an ODATA Service, there has to be an request to get the data.

Other question:

If you don't intend to bind the data from the ODATA Service to any controls - why do you want to use an ODATAModel at all?

You can simply get the data from the ODATA Service as JSON, and then work with this JSON object:


var url = "https://s3hanaxs.hanatrial.ondemand.com/p1787990323trial/myhanaxs/hello/services/service.xsodata/tbl..."

$.getJSON( url, function(data) {                      

// Loop over json object..

jQuery.each(data.d.results, function(i, val) {

console.log(i,val);

});

})

Greets,

ben

former_member184867
Active Contributor
0 Kudos

Either you can use oData model or OData object provided by datajs(available in UI5).

Example here JS Bin - Collaborative JavaScript Debugging</title> <link rel="icon" href="h...

Former Member
0 Kudos

To create a model & load data, you can do


var oModel = new sap.ui.model.odata.ODataModel(your-service-url).attachRequestCompleted(function(data){

                 console.log(data) });

The above will retrieve the data.Then, it's up to you whether you bind the model to any controls or not!