Hi I am trying to use ONLY JavaScript and HTML to GET the JSON object from an URL. I am using the following code:
<html>
<head>
<title>Json</title>
<script src="jquery-3.2.1.min.js"></script>
</head>
<body>
<button onclick="myFunction()">Start</button>
<script>
function myFunction() {
jQuery.ajax( {
url: 'https://iotmmss0018275632trial.hanatrial.ondemand.com/com.sap.iotservices.mms/v1/api/http/app.svc/T_IOT_59824470F0BD12350F22?$format=json',
type: 'GET',
crossDomain: true,
dataType: 'json',
success: function( response ) {
console.log(response);
},
error : function(error) {
console.log(error);
},
});
}
</script>
</body>
As expected I am getting
Failed to load "URL": No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost' is therefore not allowed access. The response had HTTP status code 401.
I cant configure the Server and I dont know if it supports CORS (Im new). I tried a JSONP request and got as response status code 200 and the JSON, but with the error:
Uncaught SyntaxError: Unexpected token :
So what can I do?