Access-Control-Allow-Origin Openstreetmap problem - header

Hi I'm trying to use http://nominatim.openstreetmap.org/searchformat=json&q= on a WordPress site to get long and lat from an adresse to set markers on a leaflet map and it works fine as long a I'm logged in as an admin but when I'm not I get this error
Access to XMLHttpRequest at 'http://nominatim.openstreetmap.org/search?format=json&q=3%20rue%20du%20G%C3%A9n%C3%A9ral%20Leclerc,%20Schwindratzheim' from origin 'http://isad-confort.projet-maquette.fr' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
I can't find an answers that I understand on how to set the header Access-Control-Allow-Origin, can someone explain me what I should do.

I solved it juste needed to change my request from
jQuery.get(location.protocol + '//nominatim.openstreetmap.org/search?format=json&q='
To
jQuery.get('https://nominatim.openstreetmap.org/search?format=json&q='
Thanks peeebeee

Related

Error while fetching data from GitHub API

I'm trying to get user details from the Github API using fetch, but it's showing the following error in the console
Access to fetch at 'https://api.github.com/users/a' from origin
'http://127.0.0.1:5500' has been blocked by CORS policy: No
'Access-Control-Allow-Origin' header is present on the requested
resource. If an opaque response serves your needs, set the request's
mode to 'no-cors' to fetch the resource with CORS disabled.
How to solve this problem
Even if the error message includes "CORS", there are other things wrong.
The following content that is my original answer has nothing with this question.
It is the problem of the browser and localhost not GitHub API.
(To tell the truth, GitHub API allow CORS)
Normal browsers must disturb the connection between localhost and http(s)://*.
If you want to avoid it, you should use http-server (npm install http-server -g).

Laravel and vue not submitting data not querying data from database

Helo,am new in Vue.js,am using laravel and vue to practice some crud application. It does not submit nor query data,,
It gives this error when i view on the chrome;
Access to XMLHttpRequest at 'http://localhost:8000/items' from origin 'http://laravelvue2.test' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
You need to respond with Access-Control-Allow-Origin header when accessing backend from differend domain. In this example the value of Access-Control-Allow-Origin must be http://localhost:8000.
Adding header to your response is quite easy in laravel: https://laravel.com/docs/5.7/responses#attaching-headers-to-responses
You can also use this library: https://github.com/barryvdh/laravel-cors

How to enable CORS for Catalyst

Having a Perl Catalyst application, which produces JSON, I need to read that JSON content using jQuery within an HTML page, served by an Apache server. Both applications, Catalyst and Apache are running on the same host.
When I access the Catalyst URL from Apache I get the error
Access to XMLHttpRequest at 'http://localhost:3000/abc/json_list' from origin 'http://localhost:8888' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
As I red in many topics, a header (or more) must be set. In this case the Catalyst must be set but I don't know how.
Any hint?
Catalyst allows you to set response headers using the header method on the response object.
$c->res->header( "Access-Control-Allow-Origin" => "http://localhost:8888" );
Consider using a controller's sub auto or using existing middleware if you have multiple endpoints that need to provide permission via CORS.

Vuejs 303 redirect

In my Vuejs application on calling API to make a payment and I get 303 as status code and In the header, I can see Location:
http://local.xyz.in:1024/payment-success
In the browser's network console, I can see log for
http://local.xyz.in:1024/payment-success
but the page doesn't redirect to payment-success page and show following error on the console
Failed to load http://local.xyz.in:1024/payment-success:
Response to preflight request doesn't pass access control check: No
'Access-Control-Allow-Origin' header is present on the requested
resource. Origin 'null' is therefore not allowed access.
Thank you in advance.
You are running into CORS issues. There are several ways to fix/workaround this.
Turn off CORS. For example how to turn off cors in chrome
Use a plugin for your browser

LinkedIn share API fails with "Response to preflight request doesn't pass"

i am using api call to share post on company page , when i do this from localhost it works fine, but when i put it on live VPS it fails
Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin "MY ADDRESS I REMOVED FOR MY SECURITY" is therefore not allowed access.
I have googled it and found that it is a problem with the CORS headers , i have tried to add Header set Access-Control-Allow-Origin "*" in .htaccess i set but still nothing, any and all pointers or fixes would be appreciated , thanks
i use php 5.6 and apache 2.4.18
Adding this as answer so that anyone can find it. As #HoldOffHunger suggeted.
Ok so i managed to fix this error by adding headers not only to .htaccess but also to my ajax calls and it is working, so if you have same error fix it by adding Access-Control-Allow-Origin "*" headers in ajax call, change "*" with your origin.