CORS WebService from Portal
Hi,
I'm trying to call a webservice using Ajax from the LemonLdap portal. The idea is to call the webservice when the portal is loading in order to allow the user to updates its personal data (only when certain conditions are filled).
I'm currently stuck with the following CORS errors poping in my JS console :
- Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://test-api.dev/api/users/users.php. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
- Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://test-api.dev/api/users/users.php. (Reason: CORS request did not succeed).
The virtual host test-api.dev is behind the same apache server than the portal and has the following header set :
Header set Access-Control-Allow-Origin "auth-portal.dev"
I also updated LemonLdap xml configuration to allow Ajax request to be sent to the webservice URL :
"cspConnect":"'self' http://test-api.dev"
And added a specific JS to the portal so that when the portal loads, the Ajax request is sent :
$(document).ready(
function() {
$.ajax({
type: "POST",
url: "http://test-api.dev/api/users/users.php",
success: function(result, textStatus, xhr) {
console.log(result);
}
});
}
);
With this configuration :
- When loading the portal, I get a CORS error during the Ajax call (and there is no
Access-Control-Allow-Origin
header visible in the request response) - When opening a new tab and loading manually the same URL, I can see the exported
Access-Control-Allow-Origin
header
Is there any way to call a webservice from the portal page ? Why is the Access-Control-Allow-Origin
header not showing when using Ajax ?
Thanks for your support