on ‎2018 Sep 04 3:39 PM
I'm trying to access a SAP Successfactors API from an AJAX Call in a SAPUI5 application.
I can access the API fine using POSTMAN, and providing the Basic Authentication credentials.
How do I supply these credentials directly in AJAX. I've tried numerous ways from numerous post but no method seems to work.
Response from Google Dev Tools (Console Tab)
Failed to load https://api2.successfactors.eu/odata/v2/PerPerson?$select=personId: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://webidetesting#####-#####.dispatcher.hana.ondemand.com' is therefore not allowed access.
Response from Google Dev Tools (Network Tab)
Authentication credentials are required.Please provide a valid username, password and company id
Ajax.
var aData = jQuery.ajax({
type:"GET",
contentType:"application/json",
crossDomain:true,
url:"https://api2.successfactors.eu/odata/v2/PerPerson?$select=personId",
xhrFields:{
withCredentials:true},
beforeSend:function(req){
req.setRequestHeader('Authorization','Basic '+ btoa('Username:Password'));
req.setRequestHeader('Access-Control-Allow-Origin','*');},
headers:{"Authorization":"Basic "+ btoa("Username"+":"+"Password"),"Access-Control-Allow-Origin":"*"},
username:"Username",
password:"Password",
dataType:"json",async:false,
success:function(data, textStatus, jqXHR){
oModel.setData({
modelData: data
});
alert("success to post");},
error:function(oError){
console.log(oError);}});
Request clarification before answering.
The solution was to setup the DESTINATION (RFC) in our on-Premise ABAP system.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Any help with this?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I got round this using a DESTINATION. This works fine for Basic Authentication but what if the Authorization is custom ? E.g :
Authorization : PreoDay xxxxxxxxxxxxxxxxxxxx.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
do you have any idea about same origin policy?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 3 | |
| 2 | |
| 2 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 | |
| 1 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.