简体   繁体   中英

SAP Hana XSJS Ajax Post - Internal Server Error

I have 2 component in my XS engine.

  1. Html file
  2. XSJS file

I call below code to get some information from database.

$.ajax({
  url: "file.xsjs?ACTION=GET_BUBBLE_CHART_DATA",
  type: "POST",
  data: JSON.stringify({ d1: "xyxyxyx" }),
  contentType: 'application/json; charset=utf-8',
  success: function(datum) {
    if (datum != "") {
      console.log(datum);
    } else {
      alert("Please Try Again");
    }
  },
  error: function(jqXHR, textStatus, errorThrown) {
    console.log(errorThrown);
  }
});

XSJS file is like below

var METHOD = $.request.method;

switch (METHOD) {
  case $.net.http.GET:
    GET();
    break;

  case $.net.http.POST:
    POST();
    break;
}

function POST() {
  var d = JSON.parse($.request.body.asString());
  var action = $.request.parameters.get("action");
  $.response.setBody(JSON.stringify(d));
  try {
    var response = null;
    switch (action) {
      case 'GET_BUBBLE_CHART_DATA':
        response = d;
        break;
      default:
      // Don't do anything
    }
    $.response.setBody(response);
    $.response.status = $.net.http.OK;
  } catch (e) {
    $.response.contentType = "text/plain";
    $.response.status = $.net.http.INTERNAL_SERVER_ERROR;
    $.response.setBody(JSON.stringify(e));
  }
}

I already searched stackoverflow and saw web.config file settings but this is not an .NET web application and Jquery Ajax Post - internal server 500 error didn't help.

If you have any idea I would appreciate.

I'm a little late, but as I understand it, you need to provide authentication details.

Just as an example, I created in the editor a .xssqlcc configuration file to configure an anonymous connection. Then in the XSSQLCC Admin panel set a DB user to access that service (you will need to look for the security guidance you have for the user. In my case, I set up a user with CRUD operations over the schema of my need).. and all my error suddenly were gone!

I hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM