Hi there!
I am trying to access HANA XSJS service from a Browser/javascript function using AJAX.
I am getting the NO-ACCESS-CONTROL-ALLOW-ORIGIN in the javascript console.
I did what was specified in the Hana Development doc.
1. I was wondering where could I have gone wrong.
2. How do I pass userId & password gathered from my html, to access HANA xsjs
3. How do I setup no-security restrictions to access HANA.
Any help in this regards will be greatly appreciated.
thanks,
-Indu
Func.xsjs : has following
function getCountries(){
var con = $.db.getConnection("HanaTestPkg::AnonConn");
var query = "SELECT * FROM \"TEST_SCHEMA\".\"COUNTRY\" ";
var pstmt = con.prepareStatement(query);
var rs = pstmt.executeQuery();
var body = "";
while (rs.next()){
body += rs.getString(1) + ":"+ rs.getString(2) +":" ;
}
rs.close();
pstmt.close();
$.response.status = $.net.http.OK;
$.response.contentType = 'application/json';
$.response.setBody(body.toString());
$.response.setBody(JSON.stringify(body));
}
.xsaccess : has following
{
"exposed": true,
"authentication": null
}
AnonConn.xssqlcc: has
{
"description" : "Anon SQL connection"
}
myHTTPDestinatiosn.xshttpdest
host = "localhost";
port = 8080;
description = "my stock-price checker";
useSSL = false;
pathPrefix = "";
authType = none;
useProxy = false;
proxyHost = "";
proxyPort = 0;
timeout = 0;
In SQL Console I executed the following:
UPDATE "_SYS_XS"."SQL_CONNECTIONS" SET username = 'SYSTEM' WHERE name = 'HanaTestPkg::AnonConn';
In Html:
<script>
function getCountries(){
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
document.getElementById("selCountries1").value
= xmlhttp.responseText;
}
}
xmlhttp.open("GET", "http://indutest.vm.cld.sr:8000/HanaTestPkg/services/Func.xsjs?cmd=getCountries", true);
xmlhttp.send();
} // getCountries
</script>