Skip to Content
0

Errors when consume a service OData

Mar 09, 2017 at 11:21 PM

70

avatar image

When i try consume I service Odata in my console show same errors.

The errors are:

OPTIONS http://.../sap/opu/odata/sap/ZGW_TRANSF_APPROVAL_SRV_02/zget_nameset/$metadata 401 (Unauthorized)



XMLHttpRequest cannot load http://.../sap/opu/odata/sap/ZGW_TRANSF_APPROVAL_SRV_02/zget_nameset/$metadata. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://webidetesting8084021-p...trial.dispatcher.hanatrial.ondemand.com' is therefore not allowed access. The response had HTTP status code 401.



Uncaught (in promise) Object {xmlDoc: document}


Uncaught (in promise) Object {message: "Failed to execute 'send' on 'XMLHttpRequest': Fail…W_TRANSF_APPROVAL_SRV_02/zget_nameset/$metadata'.", request: undefined, response: undefined}


How can I solve it?

Bellow is my controller.js

sap.ui.define([
	'jquery.sap.global',
	'sap/ui/core/Fragment',
	'sap/ui/core/mvc/Controller',
	'sap/ui/model/Filter',
	'sap/ui/model/json/JSONModel'
], function(jQuery, Fragment, Controller, Filter, JSONModel) {
	"use strict";


	var CController = Controller.extend("sap.m.sample.InputStates.C", {


		valueHelpRequest: function(oEvent) {


			
			var url = "http://.../sap/opu/odata/sap/ZGW_TRANSF_APPROVAL_SRV_02/zget_nameset";
	var oModel = new  new sap.ui.model.odata.ODataModel(url,true,"username","password");

			var that = this;
			var handleClose = function(oEvent) {


				var oSelectedItem = oEvent.getParameter("selectedItem");
				if (oSelectedItem) {
					that.byId("InputValueHelp").setValue(oSelectedItem.getTitle());
				}
				oEvent.getSource().getBinding("items").filter([]);
			};


			// Create a SelectDialog and display it; bind to the same
			// model as for the suggested items
			if (!this._valueHelpSelectDialog) {
				this._valueHelpSelectDialog = new sap.m.SelectDialog("valueHelpSelectDialog", {
					title: "Categories",
					items: {
						path: "/value",
						template: new sap.m.StandardListItem({
							title: "{CategoryName}",
							active: true
						})
					},
					search: function(oEvent) {
						var sValue = oEvent.getParameter("value");
						var oFilter = new sap.ui.model.Filter(
							"CategoryName",
							sap.ui.model.FilterOperator.Contains, sValue
						);
						oEvent.getSource().getBinding("items").filter([oFilter]);
					},
					confirm: handleClose,
					cancel: handleClose
				});


				this._valueHelpSelectDialog.setModel(model);


			} else {
				this._valueHelpSelectDialog.setModel(model);
			}
			this._valueHelpSelectDialog.open();


		}
	});


	return CController;


});
ui5
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

3 Answers

Best Answer
Gowrinath Gundu Mar 10, 2017 at 05:59 AM
0

Hello Rubens,

Run the chrome browser by disabling web security mode- type below line in run

chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security

Open the application url in the web security disabled chrome browser

Regards,

Gowrinath

Share
10 |10000 characters needed characters left characters exceeded
Srikanth KV Mar 09, 2017 at 11:27 PM
2

Issue with CORS same origin policy, check this link

Show 1 Share
10 |10000 characters needed characters left characters exceeded

I saw it but, I don't know how can I solve my problem

0
Jun Wu Mar 09, 2017 at 11:49 PM
1

if you can deploy to abap server to run, do it, don't waste time

Show 1 Share
10 |10000 characters needed characters left characters exceeded

I can't do it

0