0

For years i have sent the request to www.gebco.net, and now suddenly it stopped working: If i check the url, it is working, and the content of the url doesnt seems to have changed, here is the console output:

enter image description here

The actual code that gets and handles the data:

function getSeaDepth(lat, lon) {

var url = "https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?request=getfeatureinfo&service=wms&crs=EPSG:4326&layers=gebco_latest_2&query_layers=gebco_latest_2&BBOX=" + lat + "," + lon + "," + (lat + 0.001) + "," + (lon + 0.001) + "&info_format=text/plain&service=wms&x=20&y=20&width=900&height=600&version=1.3.0";
console.log(url);
//console.log(typeof (url));
var req = new XMLHttpRequest();
req.open('GET', url, false);

req.send(null);
if (req.status == 200)
    var str = req.responseText;

var n = str.search("value_list = '");
var m = str.lastIndexOf("'");
var newstr = str.slice(n + 14, m);
        console.log(newstr);

return (newstr);

};

  1. Could be CORS, but why now?
  2. Could be req.send(null) is no longer allowed, but how do i find out, and why now?
  3. Could also req.open('GET', url, false); is not allowed, but it has worked for years, so why now?

Or, What could it be? tnx

Additional info/update: I had this "Deprecation warning" for years, but now its actually in effect saying "Deprecation" instead of "deprecation warning" (I dont remember what it used to say, but i think it was something with warning.... enter image description here

otk
  • 357
  • 5
  • 23
  • Does this answer your question? [Why does my JavaScript code receive a "No 'Access-Control-Allow-Origin' header is present on the requested resource" error, while Postman does not?](https://stackoverflow.com/questions/20035101/why-does-my-javascript-code-receive-a-no-access-control-allow-origin-header-i) – sandrooco Jan 06 '21 at 07:27
  • 1
    It's not that nice to use `XMLHttpRequest` but you're having a different problem: cors. The backend (gebco.net) doesn't accept requests from your client host. Google will help you, this is a common problem. – sandrooco Jan 06 '21 at 07:27
  • Why have it worked for several years up til now then? That must mean that the host implemented some CORS restrictions? – otk Jan 06 '21 at 07:29
  • Yes that's probably the case. CORS settings are configured on the backend side. Maybe you need to request access from your host? – sandrooco Jan 06 '21 at 07:31
  • I understand the answer, but not 100% sure its the case here. Find it hard to believe that a free global service, with a large number of users would suddenly implement CORS, without a word about it on their site. Its a free and open service. – otk Jan 06 '21 at 07:43
  • The actual link: https://www.gebco.net/data_and_products/gebco_web_services/web_map_service/mapserv?request=getfeatureinfo&service=wms&crs=EPSG:4326&layers=gebco_latest_2&query_layers=gebco_latest_2&BBOX=65.52223166666667,7.487383333333334,65.52323166666667,7.488383333333334&info_format=text/plain&service=wms&x=20&y=20&width=900&height=600&version=1.3.0 – otk Jan 06 '21 at 08:19
  • So, i use the "insecure disable same origin" as described here: https://stackoverflow.com/questions/3102819/disable-same-origin-policy-in-chrome Running this command in RUN(as described in comment nr 4): chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security and then it works. Have the Crome Browser then enforeced more restrictions on cross-origin? And how do i solve this programatically in my XMLhttpRequest? – otk Jan 06 '21 at 08:30
  • 1
    This "hack" won't work programatically. If you're certain that it's not really this issue - you could try to implement the request with the `fetch` api (which is a standard nowadays) or a library like axios. – sandrooco Jan 06 '21 at 08:47
  • Ok, thanks. So i need to read up on the fetch API then :) And i will try to alter the code to match the existing functionality. – otk Jan 06 '21 at 08:52
  • Are you sure that Gebco provide this as a service? Weirdly I was able from my server to access it once and after that got CORS problem. – A Haworth Jan 06 '21 at 10:40

0 Answers0