cancel
Showing results for 
Search instead for 
Did you mean: 

CORS issue with UI5- XSJS application

gopalanand
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi All,

I am trying to make an application which can send data from UI5 application to HANA Xs service with complete URL.

With my use case , i can't specify destination.

Even after enabling cors settings i cant bypass the cors issue in chrome or any other web browser.

MY code is :

	var url = "https://XXXXXXXXXXXX.hana.ondemand.com/TESTUSER/recieveData.xsjs";
	var that = this;
	//myEventList = some json data
	var username = "userName";
	var password = "password";
	if (myEventList.length > 0) {
		$.ajax({
			type: "POST",
			url: url,
			dataType: 'json',
			async: false,
			beforeSend: function(xhr) {
				xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
			},
			data: JSON.stringify(myEventList),
			success: function(result) {
				myEventList = [];
			},
			error: function(response) {
				console.log(response);
			}
		});

Accepted Solutions (1)

Accepted Solutions (1)

gopalanand
Product and Topic Expert
Product and Topic Expert
0 Kudos

I went through few documentation and with some attempts found the solution for cors

You can find it in this blog How to fix cors

Answers (1)

Answers (1)

Joseph_BERTHE
Active Contributor
0 Kudos

Have you try with JSonP ?

gopalanand
Product and Topic Expert
Product and Topic Expert
0 Kudos

i tried but , there is no more cors error but the data is also not getting passed.

Can you suggest proper syntax for the call 🙂 . My code is as following.

var url = "https://XXXXXXXXXXXX.hana.ondemand.com/TESTUSER/recieveData.xsjs";
	var that = this;
	//myEventList = some json data
	var username = "userName";
	var password = "password";
	if (myEventList.length > 0) {
		$.ajax({
			type: "POST",
			url: url,
			dataType: 'json',
			async: false,
			beforeSend: function(xhr) {
				xhr.setRequestHeader("Authorization", "Basic " + btoa(username + ":" + password));
			},
			data: JSON.stringify(myEventList),
			success: function(result) {
				myEventList = [];
			},
			error: function(response) {
				console.log(response);
			}
		});