SAP HANA XSJS Ajax Post - Internal Server Error

4.7k Views Asked by At

I have 2 components 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));
  }
}

but get

Internal Server Error

I already searched stackoverflow and saw web.config file settings but this is not an .NET web application and https://stackoverflow.com/questions/22038177/jquery-ajax-post-internal-server-500-error didn't help.

If you have any idea I would appreciate.

1

There are 1 best solutions below

0
On

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.