on 07-29-2015 3:27 PM
Hi Experts,
I am working on login authentication service where i am trying to get data from oData service.
While running this odata service in chrome it is reverting actual and correct data but wrapping it up in ajax request or any other request eg : oData request "401 Unauthorized" error is coming.
Code is as follows:
sap.ui.controller("odatabinding.TablewithODATA", {
onInit: function() {
var oModel = new sap.ui.model.json.JSONModel();
var URI = encodeURI("https://<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/InspectionSet");
$.ajax({
url: URI,
success: function(result){
var data = result.value;
oModel.setData(data);
}
});
sap.ui.getCore().setModel(oModel);
},
});
I am aware of the fact that oData model should be used in this case but while checking in debugger error for result prevails. Which means request is not being hit.
Thanks in advance.
Regards,
Shalini Mathur
The error says it all; you are not authorized to perform the request. Where are your authentication details/header?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Robin,
As I have mentioned the URL is working fine on chrome and reverting data, so i thought Username and password shall not be required.
on running URL one time required credentials are as follows:
Username: smpAdmin,
Password: s3pAdmin
can u suggest how to pass these parameters in code?
Regards,
Shalini Mathur
I have tried as follows:
var oModel = new sap.ui.model.odata.ODataModel( "https://<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/InspectionSet",false, "smpAdmin", "s3pAdmin");
which again is throwing error:
Uncaught (in promise) Object {message: "Failed to execute 'send' on 'XMLHttpRequest': Fail…P/LOGIN_WITH_FIXED_USER/InspectionSet/$metadata'.", request: undefined, response: undefined}
First check that it is HTTPS or HTTP.
Then write like this.
var oModel = new sap.ui.model.odata.ODataModel("proxy/https/<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/");
Don't write entitySet name here that is InspectionSet.
Here you have to provide just the service URL. At the time of binding any table use this as path like /InspectionSet .
Here you have to provide the metadata path only.
or if this is http then write this.
var oModel = new sap.ui.model.odata.ODataModel("proxy/http/<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/");
If you are running your application for localhost then write proxy/ otherwise if you have deployed it to abap system then don't write proxy infront of URL.
Regards
Dhananjay
Hello Shalini,
Is this URL path correct? I mean have you checked this in /IWFND/GW_CLIENT transaction code in gateway system?
This can be problem of Access-Control-Allow-Origin. Have you tried running your application in another browser like Firefox or IE.
For me the below sample code works perfectly
var oModel = new sap.ui.model.odata.ODataModel(
"proxy/https/<server>:<port>/gateway/odata/SAP/LOGIN_WITH_FIXED_USER/",
false,
"smpAdmin",
"s3pAdmin");
oTable.setModel(oModel);
oTable.bindRows("/InspectionSet");
Best regards,
Rahul
User | Count |
---|---|
88 | |
23 | |
11 | |
9 | |
8 | |
5 | |
5 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.