cancel
Showing results for 
Search instead for 
Did you mean: 

ODATA - Where to set the Header

venkateswaran_k
Active Contributor
0 Kudos

Dear All

I have created a Odata service. It is working in browser.

However, It is not accessed from the Jquery Ajax

It is adviced that to include a

ls_header-name = 'Access-Control-Allow-Origin'.

ls_header-value = '<server>:<port>'.

/iwbep/if_mgw_conv_srv_runtime~set_header( ls_header ).

.

But, I am confused in which method I should add it.

Can Someone help me

My Class name

ZCL_ZGL2_DPC_EXT

My mehtod for entityt set GLLISTSET_GET_ENTITYSET

do i need to add it inthis method?

Regards,

Venkat

Accepted Solutions (0)

Answers (1)

Answers (1)

kedarT
Active Contributor
0 Kudos

Hi Venkat,

How about using below code to resolve Access-Control-Allow-Origin

function getUrl(sUrl){

  if (sUrl == '')

  return sUrl;

  if (window.location.hostname == 'localhost'){

  return "proxy" + sUrl;

  }else {

  return sUrl;

  };

  }

  var serviceUrl = getUrl('/sap/opu/odata/sap/Service_Name/');

  var oModel = new sap.ui.model.odata.ODataModel(serviceUrl,false,null,null);

sap.ui.getCore().setModel(oModel, "Model");

Hope this helps.