Skip to Content
0

Consume XSJS response text in UI5?

Oct 26, 2017 at 09:02 PM

57

avatar image

Hi All,

I was trying to set the text of the Button to currently logged in username with jQuery.ajax call. But couldn't figure out the problem here. Please help.

view.xml

<Button id="idUserBtn" icon="sap-icon://customer" tooltip="User Information" type="Transparent"/>

controller.js

var oUsername = this.getView().byId("idUserBtn");
jQuery.ajax({
  url: "https://..../services/serverLogic.xsjs",
  method: 'GET',
  dataType: 'json',
 success: function(username) {
    oUsername.setText(username);
  },
  error: function() {
   oUsername.setText("fail");
  }
});

serverLogic.xsjs

function getUsername() {
    var username = $.session.getUsername();
    return username;
}
var result = getUsername();
$.response.setBody(result);
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Shilpa Ramamurthy
Oct 27, 2017 at 06:51 AM
1

Hi,

The AJAX call to the back-end is async by default. Looks like your success handler is reached only after the screen is rendered. You can try by re-rendering your button after setting its text in the success handler.

Show 1 Share
10 |10000 characters needed characters left characters exceeded

Didn't help. My xsjs service successfully responses with the USER logged-in. But the ajax call is failing every time, no matter in which controller lifecycle hooks it resides and sets Button's text to "fail".

0
Jun Wu Oct 26, 2017 at 11:57 PM
0

your ui5 app in hana? or in another place...

Show 2 Share
10 |10000 characters needed characters left characters exceeded

Yes, it is. Native HANA application development.

0
Manjunatha Kashirudraiah

what error you have now? why not using relative url of your xsjs?

0