cancel
Showing results for 
Search instead for 
Did you mean: 

Consuming REST webservice into SAPUI5 App.

Former Member
0 Kudos

I am trying to consume REST Web service into my SAPUI5 Application.The webservice response is in JSON format. How do I bind the data coming in my application.

I get the Error : Failed to load resource: the server responded with a status of 404 (Not Found)

// The controller code is as follow :

onInit: function() {

$.ajax({

url: "http://localhost:8080/sdnext/doj/webservice/json/employees/",

type: "GET", dataType: "text",

contentType: "text/json",

success: function(data, textStatus, jqXHR) { response = data; },

error: function(xhr, status) { console.log("ERROR"); },

complete: function(xhr, status) {

var oModel = new sap.ui.model.json.JSONModel(); oModel.loadData(response); this.getView().setModel(oModel);

} });

View is in the image attached for data Binding.

Accepted Solutions (0)

Answers (3)

Answers (3)

former_member225463
Participant
0 Kudos

Hello Sushil,

Could you please show how you are binding your table. Also check in your network tab for the response. If response is coming then there is an issue with table Binding.

Thanks,

Vikash

Former Member
0 Kudos

Please find the code here. Controller code is in the Q. There is no response in the 'Network' tab.

//json model
employee: 
[
{address: "xxx",
employeeId: "xxx",
employeeName: "xxx",
jobType: "xxx",
salary: "xxx"
},
...
]

//binding in the view 

<Table id="itable" items="{/employee}">
...
<items>
<ColumnListItem>
<cells>
<Text text="{employeeId}"></Text>
<Text text="{employeeName}"></Text>
...
</cells>
</ColumnListItem>
</items>
former_member225463
Participant
0 Kudos

Hi Sushil,

If in your employee json model data is coming then you will get the records in your table. Once you gets data from backend , set that data into json model and give a namespace employee.and then set the table with the jsonmodel.

First requirement would be to get the data from the backend system.

Thanks,

Vikash

Former Member
0 Kudos

Hi Jun Wu,

I am able to get the json data when I enter it in the browser. The webservice is working fine.

I tried to make it work from my hana cloud web IDE but no luck there. Can you suggest any other way I can consume this web service into an SAPUI5 application? Maybe by Eclipse IDE ?

regards,

Sushil

former_member201114
Participant
0 Kudos

the ajax url says you are requesting an service from localhost. is this REST service also available from outside of your network? don't forget that the webide besides in the cloud platform and therefore technicaly the ajax request is send from the cloud platform network to the localhost network.

another option is a CORS error, but normaly the error message would be another.

regards,

Nils

Former Member
0 Kudos

The REST web service I created and deployed it to my tomcat server , locally. (i.e localhost:xxxx). It is accessible when the tomcat server is on.

junwu
Active Contributor
0 Kudos

i think the error msg is very clear.

are u able to get any data if you put the url in browser?