cancel
Showing results for 
Search instead for 
Did you mean: 

Consume XSJS response text in UI5?

0 Kudos

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);

Accepted Solutions (0)

Answers (2)

Answers (2)

former_member206705
Participant

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.

0 Kudos

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".

junwu
Active Contributor
0 Kudos

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

0 Kudos

Yes, it is. Native HANA application development.

junwu
Active Contributor
0 Kudos

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