Skip to Content
0
Nov 08, 2018 at 03:16 PM

How to insert data from SAP ui5 screen to database using XSJS service?

388 Views

Hi All,

This may be a repetitive question, but I find it difficult to fetch data from UI screen using AJAX POST request. Below is the code snippet of the ajax request that is a part of the index.html file

$.ajax({
url : 'https://ajrbt0xgat8bnan8-new-newjs.sg11scbh1ddd0.hec.xxxx:30033/test.xsjs',
type : 'POST',
contentType : 'application/json',
data : JSON.stringify(oEntry),
dataType : 'json',
success : function(data) {         
alert(data);
},
error : function(error) {     
alert("Error Inserting Data")
},
});

And below is the xsjs file that consumes the data

var data1 = $.request.body.asString();  
var d = JSON.parse(data1);
$.response.contentType = 'text/html';
$.response.setBody(d[0].EMAIL);
$.response.headers.set("Access-Control-Allow-Origin", "*");
$.response.status = 200;  

Problem here is the xsjs service is not invoked as I get the alert "Error Inserting Data"

Please help and guide as I'm new to SAP HANA on whole.