cancel
Showing results for 
Search instead for 
Did you mean: 

Want to Access Web Service from different domain server to local host in SAP UI5

Former Member
0 Kudos

Hi,

I am facing one issue regarding Accessing different domain OData web service. in SAP UI5.

Currently what i am doing is shown below :

        var oModel = new sap.ui.model.json.JSONModel();

        var aData = jQuery.ajax({

            type : "GET",

            contentType : "application/json",

            url : "http://domain name:port name/sap/opu/odata/SAP/ZR_SRV/YR_CODESet",

            dataType : "jsonp",

            success : function(data,textStatus, jqXHR) {

                oModel.setData({modelData : data});

                alert("success to post");

            }

        });

But i am  getting below mentioned error:

XMLHttpRequest cannot load http://domain name::8006/sap/opu/odata/SAP/ZR_SRV/YR_CODESet()?$format=json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:56167' is therefore not allowed access. The response had HTTP status code 405.

sap-ui-core.js:80 2015-07-15 20:15:14 The following problem occurred: HTTP request failed0,, -

Please provide me some helpful solution for that as i am stuck in very urgent deliverable assignment.Helpful answere will be rewarded.

Thanks,

Vinay Sharma

Accepted Solutions (0)

Answers (1)

Answers (1)

santhu_gowdaz
Active Contributor
0 Kudos

try

  url : "proxy/http/domain name:port name/sap/opu/odata/SAP/ZR_SRV/YR_CODESet",

and it showing you are testing in locally. which server you are using?

Former Member
0 Kudos

Santhosh,

I am testing in locally . After using same url : "proxy/http/domain name:port name/sap/opu/odata/SAP/ZR_SRV/YR_CODESet"  getting same error message, Could you please provide some suitable solution step by step to test on locally.

Private_Member_15166
Active Contributor
0 Kudos

This is oData model not a JSONModel.

Write like this.

        var oModel = new sap.ui.model.odata.ODataModel();

        var aData = jQuery.ajax({

            type : "GET",

            contentType : "application/xml",

            url : "http://domain name:port name/sap/opu/odata/SAP/ZR_SRV/YR_CODESet",

            dataType : "jsonp",

            success : function(data,textStatus, jqXHR) {

                oModel.setData({modelData : data});

                alert("success to post");

            }

        });

Also write like this.

url : "proxy/http/domain name:port name/sap/opu/odata/SAP/ZR_SRV/YR_CODESet",

santhu_gowdaz
Active Contributor
0 Kudos

try,

$.ajax({ 

url :"proxy/http/domain name:port name/sap/opu/odata/SAP/ZR_SRV/YR_CODESet",

   jsonpCallback : 'getJSON',   

   contentType : "application/json",   

   dataType : 'json',

   async : false,

   success : function(data, textStatus, jqXHR)

   {   

       var oModel1 = new sap.ui.model.json.JSONModel();   

       oModel1.setData(data);

       console.log(oModel1);

       var aData = oModel1.getProperty("/d/results");

          console.log(aData);

   },

   error : function (err){

   },

});

Former Member
0 Kudos

Hello Vinay,

This error is because of cross domains...

below link may helps you...

Regards,

Kiran