Repository: pimcore/pimcore (language: php)

Issue:
[Bug]: Error OpenStreetMap Cors Headers
### Pimcore version

ALL version

### Steps to reproduce

- Go to the https://demo.pimcore.fun/admin/ and login **admin / demo**
- Open a car object (ex : /Product Data/Cars/ac cars/Cobra 427)
- Set a location in the **Sale Information** tab
- An error occured each time you open the object

![image](https://github.com/pimcore/pimcore/assets/18262300/d8ca79ab-79aa-4610-b8cc-f02e52f892ec)
![image](https://github.com/pimcore/pimcore/assets/18262300/abcd6c25-e3df-4da3-99f9-95d62f4ae547)


### Actual Behavior

Hello,

I would like to report you a cross headers error when you have a GeoCoordinate field.
Indeed the URL  : https://nominatim.openstreetmap.org/reverse?format=json&lat=47.040182144807&lon=2.8125&addressdetails=1 is blocking when Pimcore try to get the location from the Latitude and longitude.
If we analyzed the console we can see that : 
`Access to XMLHttpRequest at 'https://nominatim.openstreetmap.org/reverse?format=json&lat=47.040182144806664&lon=2.8125&addressdetails=1&_dc=1690875423920' from origin 'https://demo.pimcore.fun' has been blocked by CORS policy: Request header field x-pimcore-extjs-version-major is not allowed by Access-Control-Allow-Headers in preflight response.`

So it's maybe OpenStreepMap with their policy (https://operations.osmfoundation.org/policies/nominatim/) that blocked Pimcore headers. 

Can you investigate ?

May be if you don't send the extra headers (X-Pimcore-Csrf-Token, X-Pimcore-Extjs-Version-Major, X-Pimcore-Extjs-Version-Minor) it will be working ?

Thanks



### Expected Behavior

- Open an object with a location set and don't have the Popup error ! 
- Set a location and don't have the error.



Discussion / hints:

Fix patch:
diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/helpers.js b/bundles/AdminBundle/Resources/public/js/pimcore/helpers.js
index 896ee369e89..f5e1e6fb421 100644
--- a/bundles/AdminBundle/Resources/public/js/pimcore/helpers.js
+++ b/bundles/AdminBundle/Resources/public/js/pimcore/helpers.js
@@ -3288,3 +3288,31 @@ pimcore.helpers.treeDragDropValidate = function (node, oldParent, newParent) {
 
     return true;
 };
+
+// Sends an Ajax request, it is recommended to be used when doing simple calls or to third-party services, in contrast to Ext.Ajax.request which, by default, sends extra info (eg. custom headers) that are usually needed to be working within Pimcore interface.
+pimcore.helpers.sendRequest = function (
+    method,
+    url,
+    successCallback = function (response) {},
+    failureCallback = function (response) {},
+    alwaysCallback = function (response) {}
+) {
+    const request = new XMLHttpRequest();
+
+    request.onload = function() {
+        if (this.status >= 200 && this.status < 400) {
+            successCallback(this);
+        } else {
+            failureCallback(this);
+        }
+        alwaysCallback(this);
+    };
+
+    request.onerror = function () {
+        failureCallback(this);
+        alwaysCallback(this);
+    }
+
+    request.open(method, url);
+    request.send();
+};
diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/geo/abstract.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/geo/abstract.js
index 106767dc1b1..b88146f0a34 100644
--- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/geo/abstract.js
+++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/geo/abstract.js
@@ -95,22 +95,21 @@ pimcore.object.tags.geo.abstract = Class.create(pimcore.object.tags.abstract, {
     },
 
     getSearchUrl: function (query) {
-        var url = pimcore.settings.geocoding_url_template.replace('{q}', urlencode(query));
-        return url;
+        return pimcore.settings.geocoding_url_template.replace('{q}', urlencode(query));
     },
 
     geocode: function () {
-        var address = this.searchfield.getValue();
-        Ext.Ajax.request({
-            url: this.getSearchUrl(address),
-            method: "GET",
-            success: function (response, opts) {
-                var data = Ext.decode(response.responseText);
-                if( data[0].lat !== null && data[0].lon !== null) {
-                    var map = this.getLeafletMap(data[0].lat, data[0].lon, 15);
+        const address = this.searchfield.getValue();
+        pimcore.helpers.sendRequest(
+            "GET",
+            this.getSearchUrl(address),
+            function (response) {
+                const data = Ext.decode(response.responseText);
+                if (data[0].lat !== null && data[0].lon !== null) {
+                    const map = this.getLeafletMap(data[0].lat, data[0].lon, 15);
                     this.getLeafletToolbar(map);
                 }
-            }.bind(this),
-        });
+            }.bind(this)
+        );
     }
 });
diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/geopoint.js b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/geopoint.js
index 9346575adaa..6f173acdf06 100644
--- a/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/geopoint.js
+++ b/bundles/AdminBundle/Resources/public/js/pimcore/object/tags/geopoint.js
@@ -196,40 +196,39 @@ pimcore.object.tags.geopoint = Class.create(pimcore.object.tags.geo.abstract, {
     },
 
     geocode: function () {
-        var address = this.searchfield.getValue();
-        Ext.Ajax.request({
-            url: this.getSearchUrl(address),
-            method: "GET",
-            success: function (response, opts) {
+        const address = this.searchfield.getValue();
+        pimcore.helpers.sendRequest(
+            "GET",
+            this.getSearchUrl(address),
+            function (response) {
                 const data = Ext.decode(response.responseText);
-                if(!Array.isArray(data) || data.length === 0) {
+                if (!Array.isArray(data) || data.length === 0) {
                     Ext.MessageBox.alert(t('error'), t('address_not_found') + '. <br /> <br /> ' +
                         t('possible_causes') + ':' +
-                        `<p>${t('postal_code_format_error')}</p>` );
+                        `<p>${t('postal_code_format_error')}</p>`);
 
                     return;
                 }
                 this.latitude.setValue(data[0].lat);
                 this.longitude.setValue(data[0].lon);
                 this.updateMap();
-            }.bind(this),
-        });
-
+            }.bind(this)
+        );
     },
 
     reverseGeocode: function (layerObj) {
         if (this.latitude.getValue() !== null && this.longitude.getValue() !== null) {
-            var url = pimcore.settings.reverse_geocoding_url_template.replace('{lat}', this.latitude.getValue()).replace('{lon}', this.longitude.getValue());
-            Ext.Ajax.request({
-                url: url,
-                method: "GET",
-                success: function (response, opts) {
-                    var data = Ext.decode(response.responseText);
+            const url = pimcore.settings.reverse_geocoding_url_template.replace('{lat}', this.latitude.getValue()).replace('{lon}', this.longitude.getValue());
+            pimcore.helpers.sendRequest(
+                "GET",
+                url,
+                function (response) {
+                    const data = Ext.decode(response.responseText);
                     this.currentLocationText = data.display_name;
                     layerObj.bindTooltip(this.currentLocationText);
                     layerObj.openTooltip();
-                }.bind(this),
-            });
+                }.bind(this)
+            );
         }
     },
 
diff --git a/bundles/AdminBundle/Resources/public/js/pimcore/settings/targeting/conditions.js b/bundles/AdminBundle/Resources/public/js/pimcore/settings/targeting/conditions.js
index d2c6c2935b7..4d72184df73 100644
--- a/bundles/AdminBundle/Resources/public/js/pimcore/settings/targeting/conditions.js
+++ b/bundles/AdminBundle/Resources/public/js/pimcore/settings/targeting/conditions.js
@@ -254,18 +254,18 @@ pimcore.settings.targeting.conditions = (function () {
                         var leafletMap, marker, circle;
 
                         var searchHandler = function() {
-                            var address = searchfield.getValue();
-                            Ext.Ajax.request({
-                                url: pimcore.settings.targeting.conditions.getSearchUrl(address),
-                                method: "GET",
-                                success: function (response, opts) {
-                                    var data = Ext.decode(response.responseText);
+                            const address = searchfield.getValue();
+                            pimcore.helpers.sendRequest(
+                                "GET",
+                                pimcore.settings.targeting.conditions.getSearchUrl(address),
+                                function (response) {
+                                    const data = Ext.decode(response.responseText);
                                     if (data[0].lat !== null && data[0].lon !== null) {
                                         marker.setLatLng(L.latLng(data[0].lat, data[0].lon));
                                         leafletMap.setView(L.latLng(data[0].lat, data[0].lon), 7);
                                     }
-                                }.bind(this),
-                            });
+                                }
+                            );
                         };
 
                         var searchfield = new Ext.form.TextField({
@@ -736,8 +736,7 @@ pimcore.settings.targeting.conditions = (function () {
         },
 
         getSearchUrl: function (query) {
-            var url = pimcore.settings.geocoding_url_template.replace('{q}', urlencode(query));
-            return url;
+            return pimcore.settings.geocoding_url_template.replace('{q}', urlencode(query));
         },
 
         get: function (name) {


Test patch: