Skip to Content

Consume XSJS response text in UI5?

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);
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Oct 27, 2017 at 06:51 AM

    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.

    Add comment
    10|10000 characters needed 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".

  • Oct 26, 2017 at 11:57 PM

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

    Add comment
    10|10000 characters needed characters exceeded